I am trying to create lists out of a dataframe column in pandas. My code is:
positive = tweet_df[tweet_df['updated sentiments'].equals('positive')]
The dataframe for this code is:
I have even tried using the keywords extend and append to add the appropriate data to the lists, but I am not sure why it is not checking the 'updated sentiments' column to populate the list:
pos_words = []
neg_words = []
net_words = []
for i in range(len(tweet_df['updated sentiments'])):
if tweet_df['updated sentiments'].equals('negative'):
neg_words.extend(tweet_df['Tweet Body'].tolist())
elif tweet_df['updated sentiments'].equals('positive'):
pos_words.extend(tweet_df['Tweet Body'].tolist())
else:
net_words.extend(tweet_df['Tweet Body'].tolist())
I dont think equals is the right function here. equals function compares two series or dataframes to check whether they are equal.
Instead you can use the loc function.
positive = tweet_df.loc[tweet_df['updated_sentiments']=='positive', 'Tweet Body'].tolist()