code.dev.world
code.dev.world

Reputation: 221

How can python pandas read excel file without unnamed columns

I'd like to read a .xlsx using python pandas. The problem is the at the beginning of the excel file, it has some additional data like title or description of the table and tables contents starts. That introduce the unnamed columns because pandas DataReader takes it as the columns. But tables contents starts after few lines later.

A                              B                     C
this is description
last updated: Mar 18th,2014
                               Table content
Country                        Year                 Product_output
Canada                         2017                 3002
Bulgaria                       2016                 2201
...

The table content starts in line 4. And columns must be "Country", "year", "proudct_output" instead "this is description", "unnamed", "unnamed".

Upvotes: 0

Views: 2929

Answers (2)

Himan Bayan
Himan Bayan

Reputation: 56

Try using index_col=[0] parameter pd.read_excel('Excel_Sample.xlsx',sheet_name='Sheet1',index_col=[0])

Upvotes: 0

Mikhail Venkov
Mikhail Venkov

Reputation: 378

when you use read_excel function set skiprows paramter to 3.

Upvotes: 1

Related Questions