too much additional random noise added to the portfolio using groupby you can compute exposures industry by industry to do sowrite function like sodef beta_exposure(chunkfactors=none)return pd ols( =chunkx=factorsbeta thengroup by industries and apply that functionpassing the dataframe of factor loadingsin [ ]by_ind port groupby(industriesin [ ]exposures by_ind apply(beta_exposurefactors=factorsin [ ]exposures unstack(out[ ] industry financial - tech - intercept decile and quartile analysis analyzing data based on sample quantiles is another important tool for financial analysts for examplethe performance of stock portfolio could be broken down into quartiles (four equal-sized chunksbased on each stock' price-to-earnings using pan das qcut combined with groupby makes quantile analysis reasonably straightforward as an examplelet' consider simple trend following or momentum strategy trading the & index via the spy exchange-traded fund you can download the price history from yahoofinancein [ ]import pandas io data as web in [ ]data web get_data_yahoo('spy'''in [ ]data out[ ]datetimeindex entries : : to : : data columnsopen non-null values high non-null values low non-null values close non-null values volume non-null values adj close non-null values dtypesfloat ( )int ( nowwe'll compute daily returns and function for transforming the returns into trend signal formed from lagged moving sumpx data['adj close'returns px pct_change(group transforms and analysis www it-ebooks info