2

I am doing sentiment analysis for the first time. I am analyzing yelp reviews. I have converted the reviews into a list before writing them into a csv file. I am having some coding issues with these reviews so I am running this code.

df['newtext'] = map(lambda x: x.decode('latin-1').encode('ascii','ignore'),df['comment'])

This creates a new column(newtext) but instead of getting clean text I am getting this message

map object at 0x000001C1B9CE07F0

I am using python 3. Please help. Thank you

cs95
  • 379,657
  • 97
  • 704
  • 746

4 Answers4

2

Python's map function returns map objects, which need to be cast to lists. Example

So, you can just cast your map() call in a list()

df['newtext'] = list(map(lambda x: x.decode('latin-1').encode('ascii','ignore'),df['comment']))
UserAG
  • 142
  • 7
rma
  • 1,853
  • 1
  • 22
  • 42
2

map will slow things down, especially for large dataframes. You should know string columns offer vectorized methods which are much faster than maps and loops.

The pandaic way would be to call the str accessor methods - encode and decode, which do the exact same thing, but much faster.

df['newtext'] = df.comments.str.decode('latin-1').str.encode('ascii','ignore')
cs95
  • 379,657
  • 97
  • 704
  • 746
0

Try this. It converts the map object to a list.

df['newtext'] = list(map(lambda x: x.decode('latin-1').encode('ascii','ignore'),df['comment']))
whackamadoodle3000
  • 6,684
  • 4
  • 27
  • 44
0

just convert the map object into a list as shown below

df['newtext'] = list(map(lambda x: x.decode('latin-1').encode('ascii','ignore'),df['comment']))
Max
  • 1,283
  • 9
  • 20