Here is a very simple answer my friend:
df['nb_months'] = ((df.date2 - df.date1)/np.timedelta64(1, 'M'))
and now:
df['nb_months'] = df['nb_months'].astype(int)
More Related Contents:
- Add missing dates to pandas dataframe
- Convert Excel style date with pandas
- Can pandas automatically read dates from a CSV file?
- Find the end of the month of a Pandas DataFrame Series
- Add months to a date in Pandas
- How do I convert strings in a Pandas data frame to a ‘date’ data type?
- python/pandas: convert month int to month name
- Python Pandas: Group datetime column into hour and minute aggregations
- Sort a pandas dataframe series by month name
- Matplotlib DateFormatter for axis label not working
- Splitting timestamp column into separate date and time columns
- Get week start date (Monday) from a date column in Python (pandas)?
- Pandas Merge on Name and Closest Date
- Diff of two Dataframes
- Computing np.diff in Pandas after using groupby leads to unexpected result
- changing all dates to standard date time in dataframe
- group by week in pandas
- Convert month int to month name in Pandas
- Which is the fastest way to extract day, month and year from a given date?
- Extracting dates that are in different formats using regex and sorting them – pandas
- Getting days since last occurence in Pandas DataFrame?
- Resample time series in pandas to a weekly interval
- Clean way to convert quarterly periods to datetime in pandas
- How to combine year, month, and day columns to single datetime column?
- How do I convert timestamp to datetime.date in pandas dataframe?
- Convert dates to pd.to_datetime where month could be either a number or month name
- String concatenation of two pandas columns
- How to create a large pandas dataframe from an sql query without running out of memory?
- How to add hovering annotations to a plot
- Writing a Python Pandas DataFrame to Word document