Get a List from Pandas Dataframe Column Headers

Get a list from Pandas DataFrame column headers

You can get the values as a list by doing:

list(my_dataframe.columns.values)

Also you can simply use (as shown in Ed Chum's answer):

list(my_dataframe)

Pandas Column names to list - correct method

You can also use:

df.columns.tolist()

Get list of column names of values 0 for specific row (date) in Python

Use DataFrame.loc for filter row by datetime, compare for greater like 0 and filter columns names:

print (df1.columns[df1.loc['2022-01-04'].gt(0)].tolist())
['01G', '02G', '04G']

pandas column names to list

Or, you could try:

df2 = df.columns.get_values()

which will give you:

array(['q_igg', 'q_hcp', 'c_igg', 'c_hcp'], dtype=object)

then:

df2.tolist()

which gives you:

['q_igg', 'q_hcp', 'c_igg']


Related Topics



Leave a reply



Submit