Back Navigation Next Navigation Pandas (page 7 of 9)

We can rename columns (e.g., my_df = my_df.rename(columns={'old_name': 'new_ name'}) renames the old_name Series to new_name.

We can change the index of each row (e.g., my_df = my_df.set_index('column_one') sets the row index to the values in column_one.

Pandas columns

We can also drop a column using "del col1" or "my_df.pop('col1')". Similarly, we can drop rows using my_df.drop(['r1']) to drop the row indexed with 'r1'.