How about:
df_test['Difference'] = (df_test['First_Date'] - df_test['Second Date']).dt.days
This will return difference as int
if there are no missing values(NaT
) and float
if there is.
Pandas have a rich documentation on Time series / date functionality and Time deltas
More Related Contents:
- Converting between datetime, Timestamp and datetime64
- NumPy or Pandas: Keeping array type as integer while having a NaN value
- Pandas: How to create a datetime object from Week and Year?
- pd.Timestamp versus np.datetime64: are they interchangeable for selected uses?
- Convert a column of timestamps into periods in pandas
- Replacing values represented by 'UN' with NaN
- How to print pandas DataFrame without index
- pandas select from Dataframe using startswith
- What’s the fastest way in Python to calculate cosine similarity given sparse matrix data?
- Restart cumsum and get index if cumsum more than value
- What does the term “broadcasting” mean in Pandas documentation?
- Dropping infinite values from dataframes in pandas?
- ValueError: numpy.dtype has the wrong size, try recompiling
- Convert timedelta64[ns] column to seconds in Python Pandas DataFrame
- Splitting timestamp column into separate date and time columns
- ‘DataFrame’ object has no attribute ‘sort’
- Pandas pd.Series.isin performance with set versus array
- Get year, month or day from numpy datetime64
- Get week start date (Monday) from a date column in Python (pandas)?
- What is dtype(‘O’), in pandas?
- pandas distinction between str and object types
- Python pandas convert datetime to timestamp effectively through dt accessor
- Which is the fastest way to extract day, month and year from a given date?
- Locate first and last non NaN values in a Pandas DataFrame
- Pandas custom function to find whether it is the 1st, 2nd etc Monday, Tuesday, etc – all suggestions welcome
- How to resample a dataframe with different functions applied to each column?
- Resample time series in pandas to a weekly interval
- Python: Adding hours to pandas timestamp
- How to use numpy to get the cumulative count by unique values in linear time?
- how to specify the datetime format in read_csv