Suppose I have a Pandas dataframe df has columns a,b,c,d…z . And I want to: df.groupby('a').apply(my_func()) for columns d-z, while leave column 'b' & 'c' unchanged . How to do that ?
I notice Pandas can apply different function to different column by passing a dict . But I have a long column list and just want parameters to set or tip to simply tell Pandas to bypass some columns and apply my_func() to rest of columns ? (Otherwise I have to build a long dict)
One simple (and general) approach is to create a view of the dataframe with the subset you are interested in (or, stated for your case, a view with all columns except the ones you want to ignore), and then use APPLY for that view.
Use your favorite methods to create the view you need. You could select a range of columns like so
df_view = df.ix[:,'b':'d'], but the following might be more useful for your scenario:Apply your function to that view. (Note this doesn’t yet change anything in df.)
Update the df using update()