I want my code to perform semantic analysis and create a csv table:
from collections import Counter
import pandas as pd
stoplist = ['.', 'and', 'was', 'in', 'a', 'the', ',', '?', ':', 'of']
text1 = str(input("Paste text here: "))
words1 = [s.lower() for s in text1.split() if s.lower() not in stoplist]
data = {'quantity': words1}
df = pd.DataFrame(data)
df = df['quantity'].value_counts()
df.to_csv('seo.csv')
Stoplist works for words, however it does not for punctuation:
Many people suggested using .str.replace(r'[^\w\s]+', '')
, but it doesn't work here:
AttributeError: Can only use .str accessor with string values!