out[ ]aapl msft xom spx one task of interest might be to compute dataframe consisting of the yearly correlations of daily returns (computed from percent changeswith spx here is one way to do itin [ ]rets close_px pct_change(dropna(in [ ]spx_corr lambda xx corrwith( ['spx']in [ ]by_year rets groupby(lambda xx yearin [ ]by_year apply(spx_corrout[ ]aapl msft xom spx there isof coursenothing to stop you from computing inter-column correlationsannual correlation of apple with microsoft in [ ]by_year apply(lambda gg['aapl'corr( ['msft'])out[ ] examplegroup-wise linear regression in the same vein as the previous exampleyou can use groupby to perform more complex group-wise statistical analysisas long as the function returns pandas object or scalar value for examplei can define the following regress function (using the statsmo dels econometrics librarywhich executes an ordinary least squares (olsregression on each chunk of data data aggregation and group operations www it-ebooks info