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

python繪圖pyecharts+pandas的使用詳解

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

pyecharts介紹

pyecharts 是一個用于生成 Echarts 圖表的類庫。Echarts 是百度開源的一個數(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

在這里插入圖片描述 

基礎案例

from pyecharts.charts import Bar
bar = Bar()
bar.add_xaxis(['小嘉','小琪','大嘉琪','小嘉琪'])
bar.add_yaxis('得票數(shù)',[60,60,70,100])
#render會生成本地HTML文件,默認在當前目錄生成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版本支持鏈式調(diào)用
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

# 示例數(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="我是副標題"))
    .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 標記線 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("門店數(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()

在這里插入圖片描述

在這里插入圖片描述

啊哈這個還訪問不了哈

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

在這里插入圖片描述

在這里插入圖片描述

20200822pyecharts+pandas 初步學習

作者今天學習做數(shù)據(jù)分析,有錯誤請指出
下面貼出源代碼

# 獲取數(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' 是因為作者想在jupyter上面看
with open('./國內(nèi)疫情.json','w',encoding='utf-8') as f:
  #再將python的字典轉(zhuǎn)json數(shù)據(jù)
  # json默認中文以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]
#獲取省級數(shù)據(jù)
provinceList = chinaAreaDict['children']
# 獲取的數(shù)據(jù)有幾個省市和地區(qū)
print('數(shù)據(jù)共有:',len(provinceList),'省市和地區(qū)')
#將中國數(shù)據(jù)按城市封裝,例如【{湖北,武漢},{湖北,襄陽}】,為了方便放在dataframe中
china_citylist = []
for x in range(len(provinceList)):
  # 每一個省份的數(shù)據(jù)
  province =provinceList[x]['name']
  #有多少個市
  province_list = provinceList[x]['children']
  
  for y in range(len(province_list)):
    # 每一個市的數(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['累計確診']=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ù)基礎
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)情況還是非常良好的

在這里插入圖片描述

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

相關文章

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

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

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

    Pycharm 解決自動格式化沖突的設置操作

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

    Python圖像的增強處理操作示例【基于ImageEnhance類】

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

    Linux下python3.7.0安裝教程

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

    python使用numpy計算兩個框的iou方法示例

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

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

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

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

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

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

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

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

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

    Python中Playwright?與?pyunit?結合使用詳解

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

最新評論

五常市| 抚州市| 喀喇| 当阳市| 清镇市| 兰溪市| 晋中市| 平凉市| 伊川县| 边坝县| 安陆市| 米脂县| 苍梧县| 房产| 汾阳市| 庐江县| 德昌县| 祁连县| 苏州市| 三门峡市| 上高县| 盐源县| 余干县| 香格里拉县| 博野县| 铁岭县| 土默特右旗| 铅山县| 桃园县| 开远市| 顺义区| 尉犁县| 咸丰县| 辽阳市| 保靖县| 绥芬河市| 安丘市| 神池县| 和平县| 乐东| 福建省|