0

I am working on a Dataframe in which there two column checkin date & checkout date. Initially those two columns were in string type. I have changed them to date time object and calculate days difference between then using checkout date - checkin date. Now I want to filter rows based on the stay duration. Could any one help me to do that as the difference came in also in datetime object format. Here is my code so far:

 New_Train['checkin_date']=pd.to_datetime(New_Train['checkin_date']) 
 New_Train['checkout_date']=pd.to_datetime(New_Train['checkout_date']) 

 print(New_Train.info()) 
 #Now, Checking date & checkout date type changed to date time
 New_Train['Checkin_Year'],New_Train['Checkin_Month']= 
 New_Train['checkin_date'].dt.year,New_Train['checkin_date'].dt.month 
 New_Train['Stay_Duration'] = New_Train['checkout_date']- New_Train['checkin_date']

Thanks in Advance

Molina12
  • 180
  • 1
  • 16
  • 3
    can you share the code you have so far? – David Robles May 04 '19 at 03:40
  • New_Train['checkin_date']=pd.to_datetime(New_Train['checkin_date']) New_Train['checkout_date']=pd.to_datetime(New_Train['checkout_date']) print(New_Train.info()) """ Now, Checking date & checkout date type changed to date time""" New_Train['Checkin_Year'],New_Train['Checkin_Month']= New_Train['checkin_date'].dt.year,New_Train['checkin_date'].dt.month New_Train['Stay_Duration'] = New_Train['checkout_date']- New_Train['checkin_date'] – Atreyi Datta May 04 '19 at 03:44
  • @AtreyiDatta He meant can you include it in your post with proper formatting and explanation – Reedinationer May 04 '19 at 03:45
  • Possible duplicate of [filter dataframe in pandas by a date column](https://stackoverflow.com/questions/45613501/filter-dataframe-in-pandas-by-a-date-column) – Molina12 May 04 '19 at 04:11
  • How do you want the difference? In minutes hours or minutes? Check this : https://stackoverflow.com/questions/31283001/get-total-number-of-hours-from-a-pandas-timedelta – anky May 04 '19 at 04:18

0 Answers0