Given the date column, I want to create another column diff that count how many days apart from the first date.
date diff
2011-01-01 00:00:10 0
2011-01-01 00:00:11 0.000011 days
2011-02-01 00:00:11 30.000011 days
2013-02-01 00:00:11 395.000011 days
2014-02-01 00:00:11 760.000011 days
Dates are in datetime. What I tried so far:
df = df.sort_values(['date'], ascending=True)
df.set_index('date', inplace = True)
first = df.index[0]
df['diff'] = (first - df.index.shift()).fillna(0)