col_names = list(df.columns)
lists = data.columns.to_list()
# Basic syntax:
your_dataframe.columns
# Note, if you want the column names as a list, just do:
list(your_dataframe.columns)
In [4]: import pandas as pd
In [5]: df = pd.DataFrame(columns=['A','B','C','D','E','F','G'])
In [6]: df
Out[6]:
Empty DataFrame
Columns: [A, B, C, D, E, F, G]
Index: []
lst = data.columns.values # data is dataframe
print(data.columns.values)
# Import pandas package
import pandas as pd
# making data frame
data = pd.read_csv("nba.csv")
# iterating the columns
for col in data.columns:
print(col)
df.columns = ['column1', 'column2', 'column3']
df.columns
>gapminder.columns = ['country','year','population',
'continent','life_exp','gdp_per_cap']
print(df.rename(columns={'A': 'a', 'C': 'c'}))
# to print the columns
print(df.columns)