pandas series column name code example
Example 1: pd.series.rename
>>> s = pd.Series([1, 2, 3])
>>> s
0 1
1 2
2 3
dtype: int64
>>> s.rename("my_name") # scalar, changes Series.name
0 1
1 2
2 3
Name: my_name, dtype: int64
>>> s.rename(lambda x: x ** 2) # function, changes labels
0 1
1 2
4 3
dtype: int64
>>> s.rename({1: 3, 2: 5}) # mapping, changes labels
0 1
3 2
5 3
dtype: int64
Example 2: pandas dataframe column names
print(data.columns.values)
Example 3: name columns pandas
>gapminder.columns = ['country','year','population',
'continent','life_exp','gdp_per_cap']