I have a DataFrame similar to this one below:
Dt_Customer Recency
0 2012-09-04 58
1 2014-03-08 94
2 2013-08-21 26
3 2014-02-10 26
4 2014-01-19 94
I want to slice it based on a 'Recency' condition and get the latest date, that would return this:
Dt_Customer Recency
1 2014-03-08 94
I've tried this:
df.loc[df['Recency'] == 94 | df['Dt_Customer'].max()]
But I've got this error:
TypeError: unsupported operand type(s) for |: 'int' and 'str'
Could you guys enlighten me? I'm still learning these pandas features, so any help would be appreciated. The original DataFrame is bigger than this.
Thanks
df.loc[(df['Recency'] == 94) | (df['Dt_Customer'] == df['Dt_Customer'].max())]. that gives u anORscenario. it looks as though u r after and and , in which case, u should swap the|with ```&````. The brackets ensure each condition is evaluated separatelydf.loc[(df['Recency'] == 94) | (df['Dt_Customer'] == df['Dt_Customer'].max())]