To get the name of a column in a Pandas DataFrame in Python, you can use the columns
attribute of the DataFrame object.
Here is an example:
main.py324 chars15 lines
This will output:
main.py14 chars4 lines
In the above example, df.columns
returns an Index object containing all the column names of the DataFrame. You can then iterate over this Index object or access a specific column name by its index.
gistlibby LogSnag