I have the following dataframe and I want to compare column value and predicted, if they match then I want to set the value of a column “provided” to False. I’m having difficulty doing this.
Here’s my data:
JavaScript
x
5
1
ticker periodDate value predicted
2
0 ibm 2017 150079.080 150079.080
3
1 ibm 2016 49799.140 49799.140
4
2 ibm 2015 459.016 45949.016
5
I want a new column to just have a True/False if value and predicted match. I tried this but to no avail:
JavaScript
1
9
1
def provideOrPredicted(df):
2
if df['value'] == df['predicted']:
3
df['provided'] = False
4
elif df['value'] != df['predicted']:
5
df['provided'] = False
6
print(df)
7
8
provideOrPredicted(MergedDF)
9
I get this error:
JavaScript
1
2
1
ValueError: The truth value of a Series is ambiguous. Use a.empty, a.bool(), a.item(), a.any() or a.all().
2
Advertisement
Answer
Basically, below line will check each row and boolean result will be assigned into the new column of provided
as:
JavaScript
1
2
1
df['provided'] = df['value'] == df['predicted']
2