pandas List DataFrame column names


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:


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