pandas read excel without unnamed columns

Viewed 41

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.

2 Answers

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')]

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])

Related