I have a pandas dataframe as below:
comments tags
===============================
Hello I am fine #askfine #tag1
How are you ? #ask # tag2
I have the below list of lists:
[['Hello', 'I', 'am', 'fine'], ['How', 'are', 'you', '?']]
Now, I wanted to append the below list of lists as a single column to the original dataframe.
comments tags processed_comments
==============================================================
Hello I am fine #askfine #tag1 ['Hello', 'I', 'am', 'fine']
How are you ? #ask # tag2 ['How', 'are', 'you', '?']
How do I do?
df['processed_comments'] = listOfList is not working.
Thanks
df['processed_comments']=df['comments'].str.split()processed_commentsshown is exactly same asstr.split(), howeverdf['processed_comments'] = listOfListshould work, when you say its not working what is the problem that you face while doing this?applyit like this:df['processed_comments'] = df['comments'].apply(function)dfandlistOfListare the samelen. Doublecheck thatlen(df)andlen(listOfList)align