Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR PYTHON

how to know the column number of a dataframe in pandas

In [45]: df = DataFrame({"pear": [1,2,3], "apple": [2,3,4], "orange": [3,4,5]})

In [46]: df.columns
Out[46]: Index([apple, orange, pear], dtype=object)

In [47]: df.columns.get_loc("pear")
Out[47]: 2
Source by stackoverflow.com #
 
PREVIOUS NEXT
Tagged: #column #number #dataframe #pandas
ADD COMMENT
Topic
Name
3+4 =