0

I have performed a simple calculation between two dates, and the return shows an output of "1 Days", or "2 Days" etc...

df['Days'] = df['date1'] - df['date2']

returns:
'1 Days'
'2 Days'

I'm not sure how to manipulate this? So if I wanted to filter the dataframe to return rows for less than 5 days? Would I convert unit into seconds/Hours and then of course I could filter, but how could I just filter according to '1 Days' output?

BENY
  • 317,841
  • 20
  • 164
  • 234

1 Answers1

0

You can add dt with days convert to int

df['Days'] = (df['date1'] - df['date2']).dt.days

Then you can filter it

df1=df[df['Days']<5].copy()
BENY
  • 317,841
  • 20
  • 164
  • 234
  • Thanks, very much –  Nov 21 '19 at 23:01
  • Can I ask, is there a way to exclude certain days from this calculation? For instance, only return dt.days for working days (Excluding Sunday & Saturday)? –  Nov 22 '19 at 07:52
  • @Sam https://stackoverflow.com/questions/13019719/get-business-days-between-start-and-end-date-using-pandas – BENY Nov 22 '19 at 14:50