0

I have a dataframe


rr = pd.DataFrame([['A', pd.to_datetime('2010-01-01'), 12],
                   ['A', pd.to_datetime('2010-01-01'), 6],
                   ['A', pd.to_datetime('2010-03-01'), 3]], columns = ['id','date', 'variable'])

sucht that rr :

    id  date        variable
0   A   2010-01-01  12
1   A   2010-01-01  6
2   A   2010-03-01  3

I would like to have:

    id  date    date_lead       variable
0   A   2010-01-01  2010-02-01  1
1   A   2010-02-01  2010-03-01  12
2   A   2010-02-01  2010-03-01  6
3   A   2010-03-01  NaT         3

A normal shift operation will not suffice. How do I achieve this

Rens
  • 177
  • 9

1 Answers1

0

If I understood correctly you want to add 1 day to column rr['date'] then this should work:

rr['date_lead']=rr['date']+pd.DateOffset(days=1)
Gabriele
  • 333
  • 1
  • 7