rename index pandas code example
Example 1: pandas rename index values
df.rename(index={'alpha': 'mu'})
Example 2: how to change column name in pandas
print(df.rename(columns={'A': 'a', 'C': 'c'}))
Example 3: rename dataframe index column pandas
df.index.names = ['new_name']
Example 4: how to give column names in pandas when creating dataframe
df_new = df.rename(columns={'A': 'a'}, index={'ONE': 'one'})
print(df_new)
print(df)
Example 5: python - give a name to index column
df.index.name
df.index.name = 'my_column_name'
Example 6: pandas rename column by index?
import pandas as pd
df = pd.DataFrame({'a': [1, 2], 'b': [3, 4]})
df.columns.values[0] = "b"
df.columns.values[1] = "a"
display(df)