Reputation: 215
I am trying to convert difference between two periods (having NaT values as well) into INT values. Getting error as: AttributeError: 'NatType' object has no attribute 'n'.
import pandas as pd
date_start = pd.Period('10/2018',freq='M')
df = pd.DataFrame({'id': [1, 2, 3, 4, 5, 6],
'date_end': ['2017-01', None , '2019-04','2018-06',
'2018-12', '2019-10']})
df['date_end'] = pd.PeriodIndex(pd.to_datetime(df['date_end'], format='%Y-%m'),
freq='M')
df['diff'] = date_start - df['date_end']
df['diff'].apply(lambda x: x.n)
What did I miss?
Upvotes: 0
Views: 406
Reputation:
Well, you have a None
value in the DataFrame. Try changing that None
to another date.
Upvotes: 1