Python Forum

Full Version: How to change row 2 to column header within a dataframe
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
The following would read currency exchange rate data from an excel file online, but within the workbook, table name is written on row 1, column header is written on row 2 instead.

import pandas as pd 

erdata = pd.read_csv("https://www.censtatd.gov.hk/showtablecsv.jsp?TableID=124") 
print(erdata)
Since dataframe always identifies row 1 as column header, it would incorrectly identify only two columns in the workbook. And as usual the following drop function only remove row 2 which is the real column header.

print(erdata.drop(erdata.index[0]))
How to use codes (without manual downloading and excel editing) to remove the top row and make it correctly identify row 2 as the column header?
Any help would be very appreciated.
Yes, there is an easy way built in to pandas to do exactly that. Have you looked at the docs???

https://pandas.pydata.org/pandas-docs/st...d_csv.html

Take a look at the 'header' parameter.
(Aug-20-2020, 03:42 PM)Marbelous Wrote: [ -> ]Yes, there is an easy way built in to pandas to do exactly that. Have you looked at the docs???

https://pandas.pydata.org/pandas-docs/st...d_csv.html

Take a look at the 'header' parameter.

Thank you for the prompt solution!