Home > front end >  Python: Excel to data frame : removing top rows and columns that doesnt contain 'right' da
Python: Excel to data frame : removing top rows and columns that doesnt contain 'right' da

Time:10-05

I got a rather very basic excel to Pandas issue which I am unable to get around. Any help in this regard will be highly appreciated. enter image description here

Columns A,B,C are not required. I need the highlighted data to be read/moved into a pandas dataframe.

CodePudding user response:

df = pd.read_excel('Miscel.xlsx',sheet_name='Sheet2',skiprows=8, usecols=[3,4,5,6])
df

    Date        Customers   Location    Sales
0   2021-10-05  A           NSW         12
1   2021-10-03  B           NSW         10
2   2021-10-01  C           NSW         33

If your data is small, you can also read in and then drop the Nan.

df = pd.read_excel('Miscel.xlsx',sheet_name='Sheet2',skiprows=8).dropna(how='all',axis=1)
  • Related