Skip to content Skip to sidebar Skip to footer

Use First Row As Column Names? Pandas Read_html

I have this simple one line script: from pandas import read_html print read_html('http://money.cnn.com/data/hotstocks/', flavor = 'bs4') Which works, fine, but the column names a

Solution 1:

'read_html` takes a header parameter. You can pass a row index:

read_html('http://money.cnn.com/data/hotstocks/', header =0, flavor = 'bs4')

Worth noting this caveat in the docs:

For example, you might need to manually assign column names if the column names are converted to NaN when you pass the header=0 argument

http://pandas.pydata.org/pandas-docs/stable/generated/pandas.io.html.read_html.html

Post a Comment for "Use First Row As Column Names? Pandas Read_html"