I have a pandas dataframe
0 1 2
0 pass fail warning
1 50 12 34
I am trying to convert first row as column name something like this
pass fail warning
0 50 12 34
I am currently doing this by renaming the column name
newdf.rename(columns={0: 'pass', 1: 'fail', 2:'warning'})
and then deleting the first row. Any better way to do it .
For the dataframe DF, the following line of code will set the first row as the column names of the dataframe:
DF.columns = DF.iloc[0]
I believe need to add parameter to read_html
:
df = pd.read_html(url, header=1)[0]
Or:
df = pd.read_html(url, skiprows=1)[0]
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With