I want to check whether the date I am working with is already existing in a DataFrame. If yes, I would like to add values from another DataFrame to the count column for this date's row. I no, I would like just to concat new row to the DataFrame.
My Data Frames look like this:
result_df:
date count
0 '2021-01-01' 10
1 '2021-01-02' 13
...
temp_df:
date count
0 '2021-01-02' 8
The code I am using is following:
date = '2021-01-02'
if result_df.loc[result_df['date'].isin([date])].any():
result_df.loc[result_df['date'] == date, 'count'] += temp_df['count']
else:
result_df = pd.concat([result_df, temp_df], ignore_index=True)
As a result I have following error:
ValueError: The truth value of a Series is ambiguous. Use a.empty, a.bool(), a.item(), a.any() or a.all().
Please help me to solve this issue.