1

Trying to read excel table that looks like this:

B C
A data data
data data data

but read excel doesn't recognizes that one column doesn't start from first row and it reads like this:

Unnamed : 0 B C
A data data
data data data

Is there a way to read data like i need? I have checked parameters like header = but thats not what i need.

MrDdGANGER
  • 11
  • 2

2 Answers2

0

A similar question was asked/solved here. So basically the easiest thing would be to either drop the first column (if thats always the problematic column) with

df = pd.read_csv('data.csv', index_col=0)

or remove the unnamed column via

df = df.loc[:, ~df.columns.str.contains('^Unnamed')]
cytings
  • 59
  • 9
  • Thank you for reply but i dont need to delete column, basically table i need to read has columns of different heights like i showed (A is a start of column just like B, C) so table is not pure rectangle and i cant find the way to either read or massage dataframe to be like it is in excel file. – MrDdGANGER Jul 19 '22 at 13:13
0

You can skip automatic column labeling with something like pd.read_excel(..., header=None)

This will skip random labeling.

Then you can use more elaborate computation (e.g. first non empty value) to get the labels such as df.apply(lambda s: s.dropna().reset_index(drop=True)[0])

Frederic Bazin
  • 1,530
  • 12
  • 27