-2

am new to python so the question might sound easy to experts but am trying to create a data frame in python, which will not cut the lag variable from the bottom and we will have new data frame with rows( org. data frame row + lag # ).

am trying this using "pd.concat" and shift(lag#) but no luck so far.

Ex. assume DF have 2 variable ( date and var1) then new data frame should have 3 variable (date, var1,lag_1_var1) in which "date" and "var1" column will have "NA" value at the bottom as we will be adding 1 more row (last row lag 1 of var1), so the dimension of original DF is say n*2 and new is (n +1 (as lag1))*3

Thanks in advance

  • Welcome to StackOverflow. Please take the time to read this post on [how to provide a great pandas example](http://stackoverflow.com/questions/20109391/how-to-make-good-reproducible-pandas-examples) as well as how to provide a [minimal, complete, and verifiable example](http://stackoverflow.com/help/mcve) and revise your question accordingly. These tips on [how to ask a good question](http://stackoverflow.com/help/how-to-ask) may also be useful. – jezrael Aug 31 '17 at 11:05

1 Answers1

0

Pandas has a shift function that does this.

ShreyasG
  • 766
  • 4
  • 11
  • new_lst1=df.v1.copy(); lst1=dfv1.copy(); Day1=721; lst1[:Day1]='nan'; Lag1=pd.DataFrame(lst1[:Day1].append ( new_lst1 ,ignore_index=True )); – Py_learner Sep 01 '17 at 09:21