Here is my issue
I have this DataFrame :
df = pd.DataFrame({'Date':[1,2,3],
'Paul':[8,10,13],
'Mathieu':[18,20,2],
'Jacques':[2,1,70]})
df = df.set_index('Date')
My goal is to create an IF statement with those conditions : IF the last value of the rolling mean 2 days is < the rolling mean 3 days and the fist value (Day 1) is > the last value (Day 3) then print the name of the column.
This is what I started :
def test(data):
end = data.iloc[-1]
start = data.iloc[0]
end_rolling_2D = data.rolling(2).mean().iloc[-1]
end_rolling_3D = data.rolling(3).mean().iloc[-1]
if end_rolling_2D < end_rolling_3D and start > end :
print(data.columns)
But I have this Error :
ValueError: The truth value of a Series is ambiguous. Use a.empty, a.bool(), a.item(), a.any() or a.all().
And I don't really know how to solve that.I know that the aswer should be 'Mathieu' only because he's the only one that met the conditions.
I am very new to Python, so if anyone has an idea to solve that, you are welcome!
Thank you.
Aucun commentaire:
Enregistrer un commentaire