Code 1:
df = pd.read_csv("example.csv", parse_dates=['d'])
df2 = df.set_index(['d', 'c'])
df3 = df2.groupby(level=['c'])
def function(x):
a = pd.rolling_mean(x, 3).rename(columns = {'b':'rm'})
c = pd.rolling_std(x, 3).rename(columns = {'b':'rsd'})
pd.concat([x, a, c], axis=1)
df4 = df3.apply(lambda x: function(x))
Code 2:
df = pd.read_csv("example.csv", parse_dates=['d'])
df2 = df.set_index(['d', 'c'])
df3 = df2.groupby(level=['c'])
def function(x):
x.assign(rm = lambda x: pd.rolling_mean(x, 3))
df4 = df3.apply(lambda x: function(x))
Output of df4.head() in both of the above code1 AND code 2 is a square in iPython?? I can't figure out why.
Output:
What df3 looks like:
What df looks like:



x = pd.concat([x, a, c], axis=1)?df.plot()to get that square? Can you show example of your dataframe.dfinto the terminal in ipython and then copy the data (rather than the image) , that way i can directly copy it and usepd.read_clipboard()to reproduce your issue.