I have a dataset similar to the following.
date,score
3/1/16,0.6369
5/1/16,-0.2023
6/1/16,0.04
7/1/16,0.0772
9/1/16,-0.4215
12/1/16,0.2960
15/1/16,0.25
15/1/16,0.7684
I want to apply the following conditions on the score.
Con1: if the score is >.05, count that as positive for that date
Con2: if the score is -0.05<=score <=.05, count that as neutral for that date
Con3: Else, count that as negative for that date
And add a new_column to the DataFrame alongside the score to put the 'negative'/'positive'/'neutral' result
Expected Output:
date, score, mood
3/1/16,0.6369, positive
5/1/16,-.2023, negative
6/1/16,0.04, neutral
And I have multiple scores on the same date. So, I thought of using groupby with multiple columns ('date'and 'score') and pass through the if conditions and add a new column ['mood'] to the DataFrame.
What I have tried:
df =pd.read_csv('file.csv')
def SortMood(df)
df['mood']=[] #empty column as a list in the df to store the mood
for score in df['score']:
if score>(0.05):
df['mood'].append('positive')
elif -0.05<=score <=.05:
df['mood'].append('neutral')
else:
df['mood'].append('negative')
I am aware that this function is wrong (I get a ValueError). So, any help is appreciated. Thank you.