1.创建个df
df = DataFrame({"pear": [1,2,3], "apple": [2,3,4], "orange": [3,4,5]})
2.获取列名
df.columns
3.获取列的index
df.columns.get_loc("pear")
4.更简略的方法
[df.columns.get_loc(c) for c in df.columns if c in df]
1.创建个df
df = DataFrame({"pear": [1,2,3], "apple": [2,3,4], "orange": [3,4,5]})
2.获取列名
df.columns
3.获取列的index
df.columns.get_loc("pear")
4.更简略的方法
[df.columns.get_loc(c) for c in df.columns if c in df]