Python Forum
How to change row 2 to column header within a dataframe
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How to change row 2 to column header within a dataframe
#1
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.
Reply


Messages In This Thread
How to change row 2 to column header within a dataframe - by sparkt - Aug-20-2020, 03:31 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Adding PD DataFrame column bsben 2 358 Mar-08-2024, 10:46 PM
Last Post: deanhystad
  Python Alteryx QS-Passing pandas dataframe column inside SQL query where condition sanky1990 0 772 Dec-04-2023, 09:48 PM
Last Post: sanky1990
  Difference one column in a dataframe Scott 0 663 Feb-10-2023, 08:41 AM
Last Post: Scott
  splitting a Dataframe Column in two parts nafshar 2 995 Jan-30-2023, 01:19 PM
Last Post: nafshar
  Change a numpy array to a dataframe Led_Zeppelin 3 1,155 Jan-26-2023, 09:01 PM
Last Post: deanhystad
  How to assign a value to pandas dataframe column rows based on a condition klllmmm 0 877 Sep-08-2022, 06:32 AM
Last Post: klllmmm
  renaming the 0 column in a dataframe Led_Zeppelin 5 1,633 Aug-16-2022, 04:07 PM
Last Post: deanhystad
  How to change UTC time to local time in Python DataFrame? SamKnight 2 1,659 Jul-28-2022, 08:23 AM
Last Post: Pedroski55
  Python create a spreadsheet with column and row header ouruslife 4 1,699 Jul-09-2022, 11:01 AM
Last Post: Pedroski55
  Copy a column from one dataframe to another dataframe Led_Zeppelin 17 11,705 Jul-08-2022, 08:40 PM
Last Post: deanhystad

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020