user2129623
user2129623

Reputation: 2257

Pandas excel file reading gives first column name as unnamed

I am reading xlsx file like this

df = pd.read_excel('cleaned_data.xlsx', header=0)
df = df.drop(df.columns[0], axis=1)
df.head()

enter image description here

Problem is column names coming as first row of data.

# reading data from csv file
df = pd.read_excel('cleaned_data.xlsx', header=0)
#df = df.drop(df.columns[0], axis=1)
df = df.drop(0, inplace=True)
df.head()

I tried this way but still not luck. Any suggestion?

Upvotes: 3

Views: 7621

Answers (1)

jezrael
jezrael

Reputation: 862511

One idea is use header=1:

df = pd.read_excel('cleaned_data.xlsx', header=1)

Another is skip first row:

df = pd.read_excel('cleaned_data.xlsx', skiprows=1)

Upvotes: 6

Related Questions