1# PANDAS: get column number from colomn name
2dataframe.columns.get_loc("<col_name>")
3
1In [45]: df = DataFrame({"pear": [1,2,3], "apple": [2,3,4], "orange": [3,4,5]})
2
3In [46]: df.columns
4Out[46]: Index([apple, orange, pear], dtype=object)
5
6In [47]: df.columns.get_loc("pear")
7Out[47]: 2
8
1In [48]: a
2Out[48]:
3 c1 c2
40 0 1
51 2 3
62 4 5
73 6 7
84 8 9
9
10In [49]: a.c1[a.c1 == 8].index.tolist()
11Out[49]: [4]