Suppose i have a DataFrame:
df = pd.DataFrame({'DATE_1':['2010-11-06', '2010-10-07', '2010-09-07', '2010-05-07'],
'DATE_2':['2010-12-07', '2010-11-06', '2010-10-07', '2010-08-06']})
df['DATE_1'] = pd.to_datetime(df['DATE_1'])
df['DATE_2'] = pd.to_datetime(df['DATE_2'])
So it look like:
DATE_1 DATE_2
0 2010-11-06 2010-12-07
1 2010-10-07 2010-11-06
2 2010-09-07 2010-10-07
3 2010-05-07 2010-08-06
I want to create another column DIFF
which is diffrence of DATE_2
and DATE_1
in days or months or years.
I want to have an interface like the one, which is under these words, because i'll have to create a lot of columns, similar to DIFF
from a lot of DATE_X
columns:
def date_diffrence(x, y, parameter):
if !np.isnan(x):
return (x-y)
df['DIFF'] = df.apply(date_diffrence(df['DATE_2'], df['DATE_1']))
According to this post: Difference between map, applymap and apply methods in Pandas, it seems to me, that i'm not able to create such a universal interface. Am i right?