【问题标题】:Getting AttributeError: 'Series' object has no attribute 'to_html'?获取 AttributeError:“系列”对象没有属性“to_html”?
【发布时间】:2019-01-15 12:35:27
【问题描述】:

我的代码看起来像这样,我正在尝试制作一个包含“供应商”和“折扣”列的表格

Discount_By_Suppliers = data.groupby(["Supplier"])["Discount"].sum()
Top_20_suppliers = Discount_By_Suppliers.nlargest(25)
print(Top_20_suppliers)
Top_20_suppliers.to_html('index.html')

我做错了什么?请帮忙。

【问题讨论】:

  • to_html 适用于 Dataframe 也许你应该尝试 pd.Dataframe(Top_20_suppliers).to_html("index.html")
  • 谢谢。我做了这样的事情,它对我有用。 Top_20_suppliers = Top_20_suppliers.reset_index() 重置dataFrame的索引后,我可以将数据转换为html文件。

标签: python html-table


【解决方案1】:

我只是遇到了这个,发现它没有被“回答”。正如@dimension 所说,转换为 DataFrame 然后 .to_html() 将起作用。

Top_20_suppliers = pd.DataFrame(Top_20_suppliers)
Top_20_suppliers.to_html('index.html')

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2020-11-11
    • 2019-04-22
    • 2019-07-26
    • 2020-04-04
    • 2019-09-16
    • 2017-12-12
    • 2018-05-25
    • 2019-07-07
    相关资源
    最近更新 更多