Answers for "how to extract columns names from dataframe in python"

12

python return column names of pandas dataframe

# Basic syntax:
your_dataframe.columns

# Note, if you want the column names as a list, just do:
list(your_dataframe.columns)
Posted by: Guest on October-30-2020
0

select specific column names from dataframe

import pandas
data = pandas.DataFrame({'A' : ['X', 'Y'], 
                        'B' : 1, 
                        'C' : [2, 3]})
print data[['A', 'B']]

# Output   A  B
# 0  X  1
# 1  Y  1
Posted by: Guest on January-30-2021

Code answers related to "how to extract columns names from dataframe in python"

Python Answers by Framework

Browse Popular Code Answers by Language