python - Pandas - shifting specific columns of certain rows based on a column value -


so have big data set on nfl statistics 2005 - 2016. problem is, there new category added in 2009, columns offset prior 2009. want rows have 'nfl season' column < 2009 season shift right, columns 11 second last column (so [11:-1]).

i managed way, takes long iterate on rows (about 10,000). there quicker way this? tried see if there way use .isin if row isin 'rows_to_shift', couldn't figure out how work.

and said, there's got better or more efficient way i'm not aware of while i'm still learning pandas.

here's code i've been using:

rows_to_shift = rb_df[rb_df['nfl season'] < 2009].index.tolist()  in rows_to_shift:     rb_df.iloc[[i],11:-1] = rb_df.iloc[[i],11:-1].shift(1,axis=1) 

it seems need:

rows_to_shift = rb_df[rb_df['nfl season'] < 2009].index  rb_df.iloc[rows_to_shift,11:-1] = rb_df.iloc[rows_to_shift,11:-1].shift(1,axis=1) 

Comments

Popular posts from this blog

resizing Telegram inline keyboard -

command line - How can a Python program background itself? -

php - "cURL error 28: Resolving timed out" on Wordpress on Azure App Service on Linux -