【问题标题】:Grabbing multiple tables with pd.read_html使用 pd.read_html 抓取多个表
【发布时间】:2017-04-22 21:09:46
【问题描述】:

我正在尝试从谷歌财务获取公司财务的表格数据。这是我的代码:

    url = 'https://www.google.com/finance?q=googl&fstype=ii'
    dfs = pd.read_html(url, flavor='html5lib')
    writer = pd.ExcelWriter('output.xlsx', engine='xlsxwriter')
    for df in dfs:
        print(df)
        df.to_excel(writer, sheet_name='Sheet1')
        writer.save()

但是,当我 print(df) 时返回的是所有表格数据,但保存到 excel 中的只是收入表的季度数据表格。有谁知道为什么不将所有数据都保存到excel?任何帮助将不胜感激。

谢谢!

【问题讨论】:

    标签: python pandas html-table


    【解决方案1】:

    看起来程序在循环过程中覆盖了同一工作表/位置中的每个数据帧。

    For 需要将每个数据框写入一个新工作表或将每个数据框放置在同一个工作表中。

    请参阅 XlsxWriter 文档中的这些示例:

    【讨论】:

      猜你喜欢
      • 2021-11-10
      • 2021-12-10
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-05-17
      • 1970-01-01
      • 2020-07-08
      • 2014-02-12
      相关资源
      最近更新 更多