You can use the following syntax to change the column names in a pandas DataFrame to lowercase:
df.columns = df.columns.str.lower()
The following example shows how to use this syntax in practice.
Example: Change Column Names to Lowercase in Pandas
Suppose we have the following pandas DataFrame:
import pandas as pd #create DataFrame df = pd.DataFrame({'Team': ['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H'], 'Points': [18, 22, 19, 14, 14, 11, 20, 28], 'ASSISTS': [5, 7, 7, 9, 12, 9, 9, 4], 'Rebounds': [11, 8, 10, 6, 6, 5, 9, 12]}) #view DataFrame print(df)
Notice that none of the column names are currently lowercase.
We can use the following syntax to change all column names to lowercase:
#convert all column names to lowercase df.columns = df.columns.str.lower() #view updated DataFrame print(df) team points assists rebounds 0 A 18 5 11 1 B 22 7 8 2 C 19 7 10 3 D 14 9 6 4 E 14 12 6 5 F 11 9 5 6 G 20 9 9 7 H 28 4 12
Notice that all four column names have now been converted to lowercase.
Note that we can also use the following syntax to list out all of the column names without displaying any of the column values:
#display all column names
list(df)
['team', 'points', 'assists', 'rebounds']
We can see that each of the column names has been converted to lowercase.
Additional Resources
The following tutorials explain how to perform other common functions with columns of a pandas DataFrame:
How to Drop Columns in Pandas
How to Apply a Function to Selected Columns in Pandas
How to Change the Order of Columns in Pandas DataFrame