当前位置: 代码迷 >> 综合 >> 1980~2010年美国热狗大胃王比赛成绩柱形图__两种简单实现方式
  详细解决方案

1980~2010年美国热狗大胃王比赛成绩柱形图__两种简单实现方式

热度:74   发布时间:2023-12-06 21:31:37.0

1.首先读取文件,观察数据发现只需要第一列和第三列

filename = 'data/hot-dog-contest-winners.csv'
df = pd.read_csv(filename)
df.head()

2.提取所需要的数据 并 用 pyecharts 作图

pd.read_csv() 实现

import pandas as pd
from pyecharts.charts  import Bar
import pyecharts.options as optsfilename = 'data/hot-dog-contest-winners.csv'
df = pd.read_csv(filename)x=df['Year'].tolist()y=df['Dogs eaten'].tolist()c = (Bar().add_xaxis(x).add_yaxis('食量',y).set_global_opts(yaxis_opts=opts.AxisOpts(splitline_opts=opts.SplitLineOpts(is_show=True)))#.set_series_opts(label_opts=opts.LabelOpts(is_show=False))
)c.render_notebook()

 

with open() as f: 实现

import pandas as pd
from pyecharts.charts  import Bar
import pyecharts.options as opts
import csvx = []
y = []filename = 'data/hot-dog-contest-winners.csv'flag=0with  open(filename) as f:data = csv.reader(f)  for datarow in data:if flag==0:flag=1continuex.append(datarow[0])y.append(datarow[2])c = (Bar().add_xaxis(x).add_yaxis('食量',y).set_global_opts(yaxis_opts=opts.AxisOpts(splitline_opts=opts.SplitLineOpts(is_show=True))))c.render_notebook()