I am reading an Excel file, and I want to extract some tables from it, and put the same header for each of them.
It is now taking the first row as the header, while the actual header is the 3rd row.
Here is what I did:
new_header = df.iloc[1]
df = df[3:] #choose the data
df.rename(columns = new_header)
But it does not change the header row. Any help is appreciated.
UPDATE:
@EdChum's answer solves the header issue. However I have problem with the format of the header. The header is date in the format of Month-Year and I want to keep it that way. But when it reades it, it changes the format to "2014-01-01 00:00:00". I wrote the following peice to fix it, but it only changes the firt cell format and thus, cannot use it as the new header.
new_header = datetime.datetime.strptime("2014-01-01 00:00:00", '%Y-%m-%d %H:%M:%S').strftime('%b-%y')
pd.to_datetime, trydf.columns = pd.todatetime(df.columns)