I have a pandas dataframe, 'df' where there is a source column with dates in a date and time format. I set the hard date as a variable:
hard_date = datetime.date(2013, 5, 2)
Then I created a new column in my df with the difference between the values in the date column and hard_date ...
df['days_from'] = df['date'] - hard_date
This led to a good result. for example, when I print the first cell in a new column, it shows:
print (df['days_from'].iloc[0])
28 days 00:00:00
But now I want to convert the new column to only the number of days as an integer. I thought about just taking the first 2 characters, but many of the values are negative, so I'm looking for a better route.
Any thoughts on an efficient way to convert a column to integer days?
thank
source
share