python製図pyecharts+pandsの使用詳細


pyecharts紹介
pyechartsはEchartsのグラフを生成するためのクラスです。EchartsはBaiduのオープンソースのデータ可視化JSライブラリです。Echartsで生成した図の可視化効果は素晴らしいです。
描画漏れを避けるために、すべてのインストールを推奨します。
ダウンロードが遅くならないように、作者は全部ミラーソースを使ってダウンロードしました。

pip install -i https://pypi.tuna.tsinghua.edu.cn/simple/ echarts-countries-pypkg
pip install -i https://pypi.tuna.tsinghua.edu.cn/simple/ echarts-china-provinces-pypkg
pip install -i https://pypi.tuna.tsinghua.edu.cn/simple/ echarts-china-cities-pypkg
pip install -i https://pypi.tuna.tsinghua.edu.cn/simple/ echarts-china-counties-pypkg
pip install -i https://pypi.tuna.tsinghua.edu.cn/simple/ echarts-china-misc-pypkg
pip install -i https://pypi.tuna.tsinghua.edu.cn/simple/ echarts-united-kingdom-pypkg
在这里插入图片描述 
基礎判例

from pyecharts.charts import Bar
bar = Bar()
bar.add_xaxis(['  ','  ','   ','   '])
bar.add_yaxis('   ',[60,60,70,100])
#render     HTML  ,         render.html
# bar.render()
#        ,  bar.render("mycharts.html")
#      jupyter   ,  bar.render_notebook()
bar.render_notebook()
在这里插入图片描述

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

#     
cate = ['Apple', 'Huawei', 'Xiaomi', 'Oppo', 'Vivo', 'Meizu']
data1 = [123, 153, 89, 107, 98, 23]
data2 = [56, 77, 93, 68, 45, 67]

# 1.x        
bar = (Bar()
    .add_xaxis(cate)
    .add_yaxis('  ', data1)
    .add_yaxis('  ', data2)
    .set_global_opts(title_opts=opts.TitleOpts(title="  ", subtitle="  "))
   )
bar.render_notebook()
在这里插入图片描述

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

#     
cate = ['Apple', 'Huawei', 'Xiaomi', 'Oppo', 'Vivo', 'Meizu']
data = [153, 124, 107, 99, 89, 46]

pie = (Pie()
    .add('', [list(z) for z in zip(cate, data)],
      radius=["30%", "75%"],
      rosetype="radius")
    .set_global_opts(title_opts=opts.TitleOpts(title="Pie-    ", subtitle="     "))
    .set_series_opts(label_opts=opts.LabelOpts(formatter="{b}: {d}%"))
   )

pie.render_notebook()
在这里插入图片描述

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

#     
cate = ['Apple', 'Huawei', 'Xiaomi', 'Oppo', 'Vivo', 'Meizu']
data1 = [123, 153, 89, 107, 98, 23]
data2 = [56, 77, 93, 68, 45, 67]

"""
     :
1. is_smooth    OR   
2. markline_opts     OR    
"""
line = (Line()
    .add_xaxis(cate)
    .add_yaxis('    ', data1, 
         markline_opts=opts.MarkLineOpts(data=[opts.MarkLineItem(type_="average")]))
    .add_yaxis('  ', data2, 
         is_smooth=True, 
         markpoint_opts=opts.MarkPointOpts(data=[opts.MarkPointItem(name="      ", 
                                       coord=[cate[2], data2[2]], value=data2[2])]))
    .set_global_opts(title_opts=opts.TitleOpts(title="Line-    ", subtitle="     "))
   )

line.render_notebook()
在这里插入图片描述

from pyecharts import options as opts
from pyecharts.charts import Geo
from pyecharts.globals import ChartType
import random

province = ['   ', '   ', '   ', '   ', '   ', '   ', '   ', '  ']
data = [(i, random.randint(200, 550)) for i in province]

geo = (Geo()
    .add_schema(maptype="  ")
    .add("   ", data,
      type_=ChartType.HEATMAP)
    .set_series_opts(label_opts=opts.LabelOpts(is_show=False))
    .set_global_opts(
      visualmap_opts=opts.VisualMapOpts(),
      legend_opts=opts.LegendOpts(is_show=False),
      title_opts=opts.TitleOpts(title="      "))
   )

geo.render_notebook()
在这里插入图片描述
在这里插入图片描述
えっと、これはまだ訪問できません。
ImportError:Missing optional dependency‘xlrd’=1.0.0 for Excel support Use pip or conda to install xlrd.
在这里插入图片描述
在这里插入图片描述
20200082 pyecharts+pands予備学習
作者は今日勉強してデータの分析をします。
下にソースコードを貼り付けます。

#     
import requests
import json
china_url = 'https://view.inews.qq.com/g2/getOnsInfo?name=disease_h5'
#foreign_url = 'https://view.inews.qq.com/g2/getOnsInfo?name=disease_foreign'
headers = {
  'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/84.0.4147.125 Safari/537.36 Edg/84.0.522.59',
  'referer': 'https://news.qq.com/zt2020/page/feiyan.htm'
}
#  json  
response = requests.get(url=china_url,headers=headers).json()

print(response)
#  json    python   
data = json.loads(response['data'])

#         encoding='utf-8'        jupyter   
with open('./    .json','w',encoding='utf-8') as f:
  #  python    json  
  # json     ASCII                 False
  #indent=2:    2 

  f.write(json.dumps(data,ensure_ascii=False,indent=2))
Json形式に変換して出力するファイル
在这里插入图片描述

#  json     Excel 
import pandas as pd
#    
with open('./    .json',encoding='utf-8') as f:
  data = f.read()
  
#     python    
data = json.loads(data)
type(data)#    
lastUpdateTime = data['lastUpdateTime']
#        
chinaAreaDict = data['areaTree'][0]
#      
provinceList = chinaAreaDict['children']
#              
print('    :',len(provinceList),'     ')
#          ,  【{  ,  },{  ,  }】,      dataframe 
china_citylist = []
for x in range(len(provinceList)):
  #         
  province =provinceList[x]['name']
  #     
  province_list = provinceList[x]['children']
  
  for y in range(len(province_list)):
    #        
    city = province_list[y]['name']
    #        
    total = province_list[y]['total']
    #      
    today = province_list[y]['today']
    china_dict = {'  ':province,
           '  ':city,
           'total':total,
           'today':today
           }
    china_citylist.append(china_dict)


chinaTotaldata = pd.DataFrame(china_citylist)
nowconfirmlist=[]
confirmlist=[]
suspectlist=[]
deadlist=[]
heallist=[]
deadRatelist=[]
healRatelist=[]

#      chinaTotaldata     dataframe
for value in chinaTotaldata['total'] .values.tolist():#    
  confirmlist.append(value['confirm'])
  suspectlist.append(value['suspect'])
  deadlist.append(value['dead'])
  heallist.append(value['heal'])
  deadRatelist.append(value['deadRate'])
  healRatelist.append(value['healRate'])
  nowconfirmlist.append(value['nowConfirm'])
  
chinaTotaldata['    ']=nowconfirmlist  
chinaTotaldata['    ']=confirmlist
chinaTotaldata['  ']=suspectlist
chinaTotaldata['  ']=deadlist
chinaTotaldata['  ']=heallist
chinaTotaldata['   ']=deadRatelist
chinaTotaldata['   ']=healRatelist

#  today 
today_confirmlist=[]
today_confirmCutlist=[]

for value in chinaTotaldata['today'].values.tolist():
  today_confirmlist.append(value['confirm'])
  today_confirmCutlist.append(value['confirmCuts'])
chinaTotaldata['    ']=today_confirmlist
chinaTotaldata['    ']=today_confirmCutlist

#  total          
chinaTotaldata.drop(['total','today'],axis=1,inplace=True)

#      excel 
from openpyxl import load_workbook
book = load_workbook('    .xlsx')
#        
writer = pd.ExcelWriter('    .xlsx',engine='openpyxl')
writer.book = book
writer.sheets = dict((ws.title,ws) for ws in book.worksheets)
chinaTotaldata.to_excel(writer,index=False)
writer.save()
writer.close()

chinaTotaldata
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
作者のこちら側はまだ国外のがありますが、分かち合うつもりはありません。皆さんは見てみてください。総じて国内の状況はとてもいいです。
在这里插入图片描述
ここでは、pythonのグラフィックpyecharts+pandsに関する詳細な文章を紹介します。pyecharts pandsの使用内容については、以前の文章を検索したり、下記の関連記事を見たりしてください。これからもよろしくお願いします。