So I have a dataframe full of an entire universe of stock tickers. They are MultiIndexed by ticker and then date. What I am trying to do is normalize one of the indicator columns only for that subset of the data. For example I would want a to normalize the data on a rolling Zscore for ind1 only based on the ticker A, then the same for ticker B and so on and so forth. I am able to apply this normalization to a slice of the dataframe iteratively but I am looking for a way to easily apply this rolling normalizationn without slicing by ticker.
This is the Zscore normalization I am using but I want to apply it to each ticker subset in the dataframe without slicing and then reappending to a new dataframe.
df['normalizedInd1'] = (df['ind1'] - df['ind1'].rolling(30).mean()) / df['ind1'].rolling(30).std()
And this is a sample of the dataframe structure
secid ind1 ind2
ticker date
A 2011-01-03 101149.0 100792.5533 177960.0
2011-01-04 101149.0 127658.3339 304624.0
2011-01-05 101149.0 122648.9491 77050.0
B 2011-01-06 101150.0 110161.8415 151825.0
2011-01-10 101150.0 112800.4117 378804.0
2011-01-11 101150.0 79074.8645 525628.0