I am trying to compare multiple columns and assign the boolean value to a new column called New Column. Please find the sample data below.
df = pd.DataFrame({
'date1':['2000-03-01', '2000-03-02'],
'date2':['2000-04-01', '2000-02-02'],
'date3':['2000-05-01','2000-03-02']
})
print(df)
This is my attempt:
df['New Column'] = '0'
df.loc[df['date1'] <= df['date2'] <= df['date3'] , 'New Column'] = '1'
However, this is now working and giving me error ValueError: The truth value of a Series is ambiguous. Use a.empty, a.bool(), a.item(), a.any() or a.all().
Why is this happening and how can I solve it please? This does not seem to be a problem in other programming languages but in python. Can anyone help me understand the problem here?
Aucun commentaire:
Enregistrer un commentaire