For that you can use .get_loc() function, refer the following code:
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
Usually access by name like (df["pear"], df[["apple", "orange"]], or df.columns.isin(["orange", "pear"]))
If you want to learn more about Pandas then visit this Python Course designed by the industrial experts.