Python / Pandas - 创建HTML表

时间:2018-03-09 11:27:35

标签: python pandas

所以我现在正在做一些基本的代码,遵循一个教程,但我一直在生成一个真正的表。

我的代码是:

from pandas import DataFrame, read_csv
import matplotlib.pyplot as plt
import pandas as pd 
import sys 
import matplotlib 
df = pd.read_csv("TB_burden_countries_2018-03-06.csv")
df = df.set_index(['country'])
df2 = df.loc["United States of America","e_mort_num"]
df = pd.DataFrame(data = df2, columns=["e_mort_num"])
print(df)
df.to_csv('example.csv')
df.to_csv('example.html')

输出是:

                          e_mort_num
country                             
United States of America        1400
United States of America        1400
United States of America        1300
United States of America        1200
United States of America        1100
United States of America        1000
United States of America         990
United States of America         890
United States of America         900
United States of America         790
United States of America         800
United States of America         730
United States of America         670
United States of America         700
United States of America         620
United States of America         620
United States of America         610

但是,当我查看我创建的html文件时,它不会生成如上所示的表,但如下所示:

country,e_mort_num United States of America,1400 United States of America,1400 United States of America,1300 United States of America,1200 United States of America,1100 United States of America,1000 United States of America,990 United States of America,890 United States of America,900 United States of America,790 United States of America,800 United States of America,730 United States of America,670 United States of America,700 United States of America,620 United States of America,620 United States of America,610

关于我做错的任何建议?

0 个答案:

没有答案