2808 explained code solutions for 75 technologies


python-pandasGet dataframe column names


import pandas as pd

data = pd.DataFrame({
  'Phone': ['ip5', 'ip6', 'ip8', 'sms', 'xi'],
  'Phone Price': [204, 304, 404, 405, 305]
})
columns = data.columnsctrl + c
import pandas as pd

load Pandas module

pd.DataFrame

creates Pandas DataFrame object

.columns

returns list of columns for dataframe


Usage example

import pandas as pd

data = pd.DataFrame({
  'Phone': ['ip5', 'ip6', 'ip8', 'sms', 'xi'],
  'Phone Price': [204, 304, 404, 405, 305]
})
columns = data.columns

print(columns)
print(columns[0]) # 1st col
print(columns[1]) # 2nd col
output
Index(['Phone', 'Phone Price'], dtype='object')
Phone
Phone Price