import pandas as pd
df = pd.DataFrame({
'Name': ['John', 'Eric', 'Rick'],
'Score': [200, 500, 100\]
})
df_columns = df.columns.values.tolist()
print(df_columns)
#prints - ['Name', 'Score']
In the code snippet, we have created a DataFrame df which has two columns Name and Score. If we want to get the list of column names we can use the below syntax.
df.columns.values.tolist()
0 Comments