Home > Mobile >  Read excel sheet starting from specific col
Read excel sheet starting from specific col

Time:10-14

I have an excel workbook with multiple sheets and I am trying to import/read the data starting from any empty col before col C.

the row data look like this

A C
One Two Three

and I am trying to get the data

C
Two Three

I can't use usecols as the position of this empty col changes in each sheet I have in the workbook. So it will optimal to start always from whatever empty col located before col C

I have tried this but didn't work out for me.

df = df[df.columns[list(df.columns)[-1]]

I would appreciate any suggestions or hints. Many thanks in advance!

CodePudding user response:

Assuming your column name is an empty string(''), try slicing:

df.loc[:, '':]

CodePudding user response:

If need solution for return all values if not exist empty string use:

m1 = df.columns.str.startswith('Unnamed')
m2 = (df.columns == 'C').cumsum() == 0

m = m1 & m2

print (df.iloc[:, m[::-1].argmax():])
  • Related