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
Convert HTML Entities to Unicode and Vice Versa
Is There a Built in Package to Parse HTML into Dom
How to Find All Comments with Beautiful Soup
Paramiko Error When Trying to Edit File: "Sudo: No Tty Present and No Askpass Program Specified"
How to Exit Linux Terminal Using Python Script
Python Multiprocessing Linux Windows Difference
Arranging Text Files Side by Side Using Python
How to Use Python2.7 Pip Instead of Default Pip
How to Automatically Install Required Packages from a Python Script as Necessary
Programming on Samsung Chromebook
How to Use the Same Python Virtualenv on Both Windows and Linux
How to Check If a Process Is Still Running Using Python on Linux
What Is Different Between Makedirs and Mkdir of Os
Detect Socket Hangup Without Sending or Receiving
How to Read Realtime Microphone Audio Volume in Python and Ffmpeg or Similar