Closed
Description
-
I have searched the [pandas] tag on StackOverflow for similar questions.
-
I have asked my usage related question on StackOverflow.
Question about pandas
Hi there, my understanding of the df.groupby.rolling for a multi index dataframe should preserve the level-1 index, but I can't seem to get that. I am running Pandas 1.2.4. Hope that somebody can provide some insight of what is happening
x = range(0, 6)
id = ['a', 'a', 'a', 'b', 'b', 'b']
temp = pd.DataFrame(zip(id, x), columns = ['id', 'x'])
temp['sequence']=[0,1,2,0,1,2]
temp=temp.set_index(['id','sequence'])
print(temp)
x
id sequence
a 0 0
1 1
2 2
b 0 3
1 4
2 5
temp.groupby(level=0,group_keys=True).rolling(2, min_periods=1).min()
x
id
a 0.0
a 0.0
a 1.0
b 3.0
b 3.0
b 4.0
base don the online guides, I would expect the level 1 index to be preserved...but I can't understand what is currently happening at this case? or what is the correct way of doing it.
Hope that somebody can provide some insights with regards to this problem
EDIT: Edited as text for readability, apologies for posting images earlier, forgot about it while posting it just now