pandas Getting information about DataFrames List DataFrame column names


Example

df = pd.DataFrame({'a': [1, 2, 3], 'b': [4, 5, 6], 'c': [7, 8, 9]})

To list the column names in a DataFrame:

>>> list(df)
['a', 'b', 'c']

This list comprehension method is especially useful when using the debugger:

>>> [c for c in df]
['a', 'b', 'c']

This is the long way:

sampledf.columns.tolist()

You can also print them as an index instead of a list (this won't be very visible for dataframes with many columns though):

df.columns