I would like to do calculations on my x column and make a new column, for example lets try to determine the rolling standard deviation, I know how to calculate that for the full column:
df['std'] = df.x.rolling(2).std
Example of original dataframe:
id x
1 10
1 20
1 5
1 5
2 30
2 50
2 20
2 30
3 10
3 5
3 6
3 6
3 6
3 8
But I want that it will do this calculation with selecting them first by the id column.
Because now I first have to cut the data frame in separate data frames, and then paste them together after, and I think there should be a better way. But I do not know how to express this in a question so I can Google it.
So I would like to do the following:
df['std'] = df.x[id = 1].rolling(2).std()
= df.x[id = 2].rolling(2).std()
= df.x[id = 3].rolling(2).std()
I know this is not a correct way but I try to show what I want to achieve