hi,
my code below does not work, anyone knows why ?
data['categories']
[{'alias': 'mexican', 'title': 'Mexican'}, {'a...
# iterating through each record to get the title words, remove punctuation, and convert all words to lowercase.
import ast
import re
data['tags'] = ''
for ix in data.index:
# Evaluate categories as code
cat = ast.literal_eval(data['categories'][ix])
# Save tags as single string
words = ''
for tag in cat:
words += f"{tag['title']} "
# Remove punctuation
words = re.sub(r'[^\w\s]', ' ', words)
data.loc[ix, 'tags'] = ' '.join([words.lower(), str(int(data.loc[ix, 'price']))])
OUTPUT below
---------------------------------------------------------------------------
ValueError Traceback (most recent call last)
<ipython-input-90-0ec45374e90c> in <module>
5 for ix in data.index:
6 # Evaluate categories as code
----> 7 cat = ast.literal_eval(data['categories'][ix])
8
9 # Save tags as single string