最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

python繪圖pyecharts+pandas的使用詳解

 更新時(shí)間:2020年12月13日 09:40:55   作者:ElTarget  
這篇文章主要介紹了python繪圖pyecharts+pandas的使用詳解,文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧

pyecharts介紹

pyecharts 是一個(gè)用于生成 Echarts 圖表的類庫。Echarts 是百度開源的一個(gè)數(shù)據(jù)可視化 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

在這里插入圖片描述 

基礎(chǔ)案例

from pyecharts.charts import Bar
bar = Bar()
bar.add_xaxis(['小嘉','小琪','大嘉琪','小嘉琪'])
bar.add_yaxis('得票數(shù)',[60,60,70,100])
#render會(huì)生成本地HTML文件,默認(rèn)在當(dāng)前目錄生成render.html
# bar.render()
#可以傳入路徑參數(shù),如 bar.render("mycharts.html")
#可以將圖形在jupyter中輸出,如 bar.render_notebook()
bar.render_notebook()

在這里插入圖片描述

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

# 示例數(shù)據(jù)
cate = ['Apple', 'Huawei', 'Xiaomi', 'Oppo', 'Vivo', 'Meizu']
data1 = [123, 153, 89, 107, 98, 23]
data2 = [56, 77, 93, 68, 45, 67]

# 1.x版本支持鏈?zhǔn)秸{(diào)用
bar = (Bar()
    .add_xaxis(cate)
    .add_yaxis('渠道', data1)
    .add_yaxis('門店', data2)
    .set_global_opts(title_opts=opts.TitleOpts(title="示例", subtitle="副標(biāo)"))
   )
bar.render_notebook()

在這里插入圖片描述

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

# 示例數(shù)據(jù)
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="我是副標(biāo)題"))
    .set_series_opts(label_opts=opts.LabelOpts(formatter=": wppm3vysvbp%"))
   )

pie.render_notebook()

在這里插入圖片描述

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

# 示例數(shù)據(jù)
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 標(biāo)記線 OR 標(biāo)記點(diǎn)
"""
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="自定義標(biāo)記點(diǎn)", 
                                       coord=[cate[2], data2[2]], value=data2[2])]))
    .set_global_opts(title_opts=opts.TitleOpts(title="Line-基本示例", subtitle="我是副標(biāo)題"))
   )

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("門店數(shù)", 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()

在這里插入圖片描述

在這里插入圖片描述

啊哈這個(gè)還訪問不了哈

ImportError: Missing optional dependency ‘xlrd'. Install xlrd >= 1.0.0 for Excel support Use pip or conda to install xlrd.

在這里插入圖片描述

在這里插入圖片描述

20200822pyecharts+pandas 初步學(xué)習(xí)

作者今天學(xué)習(xí)做數(shù)據(jù)分析,有錯(cuò)誤請(qǐng)指出
下面貼出源代碼

# 獲取數(shù)據(jù)
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數(shù)據(jù)
response = requests.get(url=china_url,headers=headers).json()

print(response)
#先將json數(shù)據(jù)轉(zhuǎn) python的字典
data = json.loads(response['data'])

#保存數(shù)據(jù) 這里使用encoding='utf-8' 是因?yàn)樽髡呦朐趈upyter上面看
with open('./國內(nèi)疫情.json','w',encoding='utf-8') as f:
  #再將python的字典轉(zhuǎn)json數(shù)據(jù)
  # json默認(rèn)中文以ASCII碼顯示 在這里我們以中文顯示 所以False
  #indent=2:開頭空格2 

  f.write(json.dumps(data,ensure_ascii=False,indent=2))

轉(zhuǎn)換為json格式輸出的文件

在這里插入圖片描述

# 將json數(shù)據(jù)轉(zhuǎn)存到Excel中
import pandas as pd
#讀取文件
with open('./國內(nèi)疫情.json',encoding='utf-8') as f:
  data = f.read()
  
#將數(shù)據(jù)轉(zhuǎn)為python數(shù)據(jù)格式
data = json.loads(data)
type(data)#字典類型
lastUpdateTime = data['lastUpdateTime']
#獲取中國所有數(shù)據(jù)
chinaAreaDict = data['areaTree'][0]
#獲取省級(jí)數(shù)據(jù)
provinceList = chinaAreaDict['children']
# 獲取的數(shù)據(jù)有幾個(gè)省市和地區(qū)
print('數(shù)據(jù)共有:',len(provinceList),'省市和地區(qū)')
#將中國數(shù)據(jù)按城市封裝,例如【{湖北,武漢},{湖北,襄陽}】,為了方便放在dataframe中
china_citylist = []
for x in range(len(provinceList)):
  # 每一個(gè)省份的數(shù)據(jù)
  province =provinceList[x]['name']
  #有多少個(gè)市
  province_list = provinceList[x]['children']
  
  for y in range(len(province_list)):
    # 每一個(gè)市的數(shù)據(jù)
    city = province_list[y]['name']
    # 累積所有的數(shù)據(jù)
    total = province_list[y]['total']
    # 今日的數(shù)據(jù)
    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=[]

# 將整體數(shù)據(jù)chinaTotaldata的數(shù)據(jù)添加dataframe
for value in chinaTotaldata['total'] .values.tolist():#轉(zhuǎn)成列表
  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['現(xiàn)有確診']=nowconfirmlist  
chinaTotaldata['累計(jì)確診']=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列 在原有的數(shù)據(jù)基礎(chǔ)
chinaTotaldata.drop(['total','today'],axis=1,inplace=True)

# 將其保存到excel中
from openpyxl import load_workbook
book = load_workbook('國內(nèi)疫情.xlsx')
# 避免了數(shù)據(jù)覆蓋
writer = pd.ExcelWriter('國內(nèi)疫情.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

在這里插入圖片描述

在這里插入圖片描述

在這里插入圖片描述

在這里插入圖片描述

作者這邊還有國外的,不過沒打算分享出來,大家就看看,總的來說我們國內(nèi)情況還是非常良好的

在這里插入圖片描述

到此這篇關(guān)于python繪圖pyecharts+pandas的使用詳解的文章就介紹到這了,更多相關(guān)pyecharts pandas使用內(nèi)容請(qǐng)搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!

相關(guān)文章

  • python批量查詢、漢字去重處理CSV文件

    python批量查詢、漢字去重處理CSV文件

    這篇文章主要為大家詳細(xì)介紹了python批量查詢、漢字去重處理CSV文件,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2018-05-05
  • Pycharm 解決自動(dòng)格式化沖突的設(shè)置操作

    Pycharm 解決自動(dòng)格式化沖突的設(shè)置操作

    這篇文章主要介紹了Pycharm 解決自動(dòng)格式化沖突的設(shè)置操作,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過來看看吧
    2021-01-01
  • Python圖像的增強(qiáng)處理操作示例【基于ImageEnhance類】

    Python圖像的增強(qiáng)處理操作示例【基于ImageEnhance類】

    這篇文章主要介紹了Python圖像的增強(qiáng)處理操作,結(jié)合實(shí)例形式分析了使用ImageEnhance類處理圖片的亮度、對(duì)比度、色度以及銳度等相關(guān)操作技巧,需要的朋友可以參考下
    2019-01-01
  • Linux下python3.7.0安裝教程

    Linux下python3.7.0安裝教程

    這篇文章主要為大家詳細(xì)介紹了Linux下python3.7.0安裝教程,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2018-07-07
  • python使用numpy計(jì)算兩個(gè)框的iou方法示例

    python使用numpy計(jì)算兩個(gè)框的iou方法示例

    這篇文章主要介紹了python使用numpy計(jì)算兩個(gè)框的iou方法示例詳解,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪
    2023-08-08
  • python實(shí)現(xiàn)分頁效果

    python實(shí)現(xiàn)分頁效果

    這篇文章主要為大家詳細(xì)介紹了python實(shí)現(xiàn)分頁效果,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2017-10-10
  • python 列表,集合和字典的增刪改查

    python 列表,集合和字典的增刪改查

    這篇文章主要介紹了python 列表,集合和字典的增刪改查,本文分別對(duì)他們一一說明,小編覺得這篇文章寫的還不錯(cuò),需要的朋友可以參考下,希望能夠給你帶來幫助
    2021-10-10
  • Python中json文件的讀取實(shí)現(xiàn)

    Python中json文件的讀取實(shí)現(xiàn)

    在許多編程語言中,都有內(nèi)置的JSON解析器和生成器,可以方便地處理JSON數(shù)據(jù),本文主要介紹了Python中json文件的讀取實(shí)現(xiàn),具有一定的參考價(jià)值,感興趣的可以了解一下
    2023-08-08
  • python?super()函數(shù)的詳解

    python?super()函數(shù)的詳解

    這篇文章主要為大家介紹了python?super()函數(shù),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下,希望能夠給你帶來幫助
    2021-11-11
  • Python中Playwright?與?pyunit?結(jié)合使用詳解

    Python中Playwright?與?pyunit?結(jié)合使用詳解

    這篇文章主要介紹了Python中Playwright?與?pyunit?結(jié)合使用,本文通過實(shí)例代碼給大家介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下
    2023-03-03

最新評(píng)論

饶阳县| 元朗区| 安乡县| 祁门县| 靖江市| 留坝县| 防城港市| 广饶县| 上林县| 城步| 谢通门县| 新源县| 余庆县| 伊宁市| 嘉鱼县| 荃湾区| 方正县| 湟中县| 名山县| 吴堡县| 横峰县| 绥中县| 安徽省| 兰溪市| 江津市| 都安| 行唐县| 临夏县| 镇原县| 探索| 东明县| 兴义市| 南澳县| 奉化市| 嫩江县| 邢台市| 道真| 长寿区| 鄂托克旗| 宜君县| 苗栗县|