I am trying to shift the Pandas dataframe column data by group of first index. Here is the demo code:
In [8]: df = mul_df(5,4,3) In [9]: df Out[9]:
How about shift the total DataFrame object and then set the first row of every group to NaN?
dfs = df.shift(1) dfs.iloc[df.groupby(level=0).size().cumsum()[:-1]] = np.nan