0

My excel sheet contains one column whose header name can be two namely 'CITY' or 'CTY'. How to select the column in dataframe using pandas. OR operator is not working.

import pandas as pd
data = pd.read_excel(data.xlsx,index_col=None)
required_data=[]
required_data=data[['CITY' or 'CTY']]
Vivek Kumar
  • 53
  • 1
  • 5
  • Use `data.loc[:, data.columns.isin(['CITY','CTY'])]` – jezrael Jan 14 '20 at 14:36
  • along with that i have to select other columns a well – Vivek Kumar Jan 14 '20 at 14:37
  • Add columns to list `['CITY','CTY']` – jezrael Jan 14 '20 at 14:39
  • But it won't give the columns in sequence of my list...whatever column comes first in excel, it will be appearing first in dataframe – Vivek Kumar Jan 20 '20 at 08:19
  • Hi. Please take the time to read this post on [how to provide a great pandas example](http://stackoverflow.com/questions/20109391/how-to-make-good-reproducible-pandas-examples) as well as how to provide a [minimal, complete, and verifiable example](http://stackoverflow.com/help/mcve) and revise your question accordingly. These tips on [how to ask a good question](http://stackoverflow.com/help/how-to-ask) may also be useful. – jezrael Jan 20 '20 at 08:20

0 Answers0