Get HTML table into pandas Dataframe, not list of dataframe objects

前端 未结 2 489
别跟我提以往
别跟我提以往 2020-12-31 09:15

I apologize if this question has been answered elsewhere but I have been unsuccessful in finding a satisfactory answer here or elsewhere.

I am somewhat new to python

相关标签:
2条回答
  • 2020-12-31 09:42

    pd.read_html returns you a list with one element and that element is the pandas dataframe, i.e.

    df = pd.read_html(url) ###<-- List
    
    df[0] ###<-- Pandas DataFrame
    
    0 讨论(0)
  • 2020-12-31 09:50

    From http://pandas.pydata.org/pandas-docs/version/0.17.1/io.html#io-read-html, "read_html returns a list of DataFrame objects, even if there is only a single table contained in the HTML content".

    So df = df[0].dropna(axis=0, thresh=4) should do what you want.

    0 讨论(0)
提交回复
热议问题