这个python题怎么做,求助大佬

 

用pycharts做表格就好了。

 

您好,我是有问必答小助手,您的问题已经有小伙伴解答了,您看下是否解决,可以追评进行沟通哦~

如果有您比较满意的答案 / 帮您提供解决思路的答案,可以点击【采纳】按钮,给回答的小伙伴一些鼓励哦~~

ps:问答VIP仅需29元,即可享受5次/月 有问必答服务,了解详情>>>https://vip.csdn.net/askvip?utm_source=1146287632

先做个静态的哈,有时间再改成动态读取xlsx数据的。

from pyecharts.charts import Bar
from pyecharts import options as opts

def gen_bar():
    bar = Bar(opts.InitOpts(
        width="900px",
        height="500px",
        renderer = "svg",
        theme = "white")
    )
    bar.add_xaxis(["2009", "2010", "2011", "2012", "2013", "2014"])
    bar.add_yaxis("总案件数", [30, 31, 34, 26, 32, 22])
    bar.add_yaxis("减轻", [17, 21, 18, 10, 15, 13])
    bar.add_yaxis("加重", [2, 3, 5, 3, 8, 2])
    bar.add_yaxis("宣告无罪", [5, 4, 3, 4, 2, 2])
    bar.add_yaxis("发回重申", [5, 6, 6, 7, 8, 4])
    bar.add_yaxis("其他", [1, 0, 1, 2, 0, 1])
    # bar.set_colors(["blue", "orange", "green", "red", "purple", "brown"])
    bar.set_global_opts(title_opts=opts.TitleOpts(
                            title='2009-2014年度改判发回案件总体情况',
                            pos_left='middle'),
                        legend_opts=opts.LegendOpts(
                            is_show=True,
                            pos_left='right',
                            pos_bottom='20%',
                            orient='vertical',
                            padding=5,
                            item_gap=20,
                            item_width=30),
                        xaxis_opts=opts.AxisOpts(
                                name='年份',
                                name_location='middle',
                                name_gap=20),
                        yaxis_opts = opts.AxisOpts(
                                name='改判情况',
                                name_location='middle',
                                name_gap=30)
                        )
    bar.render()


if __name__ == "__main__":
    gen_bar()


运行后得到render.html文件,浏览器打开效果如下:

 

1.用pandas创建一个数据框df,然后用df.to_excel()写入文件;

2.用matplotlib画柱状图