欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

如何對csv文件數(shù)據(jù)分組,并用pyecharts展示

 更新時(shí)間:2022年11月01日 11:09:01   作者:陳年椰子  
這篇文章主要介紹了如何對csv文件數(shù)據(jù)分組,并用pyecharts展示,具有很好的參考價(jià)值,希望對大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教

在處理csv文件時(shí),會(huì)有些數(shù)據(jù)需要分組展示。

比如以下文件及統(tǒng)計(jì)效果

為了避免重復(fù)勞動(dòng),

把pandas 和 pyecharts 做了個(gè)結(jié)合

# coding=UTF-8
 
from pyecharts import Bar,Scatter,Line
from pyecharts import Page
import pandas as pd
# 生成的HTML文件在程序目錄 render.html
 
def create_line(x_data, line_data_head, line_data, line_dict):
    # 建立一個(gè)Line圖返回
    # x_data X 軸數(shù)據(jù)
    # bar_data_head  數(shù)據(jù)列
    # bar_data 數(shù)據(jù)數(shù)組二維,數(shù)量和數(shù)據(jù)列匹配, 組內(nèi)數(shù)據(jù)和 X軸數(shù)據(jù)匹配
    # bar_dict 字典 , 標(biāo)題, 副標(biāo)題 , 長 , 寬
    line = Line(line_dict['title'], line_dict['subtitle'], width=line_dict['width'], height=line_dict['height'])
    for i in range(len(line_data_head)):
        line.add(line_data_head[i], x_data, line_data[i], xaxis_interval=0, is_smooth=True)
    return line
 
 
def lines_show(line_data):
    # 顯示多個(gè)曲線圖
    page = Page()
    for b in line_data:
        line = create_line(b['x'], b['head'], b['data'], b['dict'])
        page.add(line)
    page.render()
 
 
def create_bar(x_data, bar_data_head, bar_data, bar_dict):
    # 建立一個(gè)Bar圖返回
    # x_data X 軸數(shù)據(jù)
    # bar_data_head  數(shù)據(jù)列
    # bar_data 數(shù)據(jù)數(shù)組二維,數(shù)量和數(shù)據(jù)列匹配, 組內(nèi)數(shù)據(jù)和 X軸數(shù)據(jù)匹配
    # bar_dict 字典 , 標(biāo)題, 副標(biāo)題 , 長 , 寬
    bar = Bar(bar_dict['title'], bar_dict['subtitle'], width=bar_dict['width'], height=bar_dict['height'])
    for i in range(len(bar_data_head)):
        bar.add(bar_data_head[i], x_data, bar_data[i], xaxis_interval=0)
    return bar
 
 
def bars_show(bar_data):
    # 顯示多個(gè)柱狀圖
    page = Page()
    for b in bar_data:
        bar = create_bar(b['x'], b['head'], b['data'], b['dict'])
        page.add(bar)
    page.render()
 
 
def csv_data_show(csv_file, x_head_key, data_key, m_yw):
    # 讀取CSV 文件,獲取多列數(shù)據(jù),顯示相關(guān)圖示
    df = pd.read_csv(csv_file, sep=',', encoding='gb2312')
    cols_len = len(df.columns)
    rows_len = len(df)
    x_head = [str(c).strip() for c in df[x_head_key]]
    print '數(shù)據(jù)列', cols_len, '數(shù)據(jù)行', rows_len, 'X軸數(shù)據(jù)', len(x_head),  '圖數(shù)', len(data_key)
 
    yw_list = []
    for m_data in data_key:
        m_list = []
        m_list_head = []
        for i in m_data:
            di = [d for d in df[df.columns[i]]]
            m_list.append(di)
            m_list_head.append(df.columns[i])
        yw_i = {
            'x': x_head,
            'head': m_list_head,
            'data': m_list,
            'dict': m_yw
        }
        yw_list.append(yw_i)
    bars_show(yw_list)
    # lines_show(yw_list)
 
 
def csv_data_show_comb(csv_file, x_head_key, comb_key, data_key, m_yw):
    # 讀取CSV 文件,獲取單列數(shù)據(jù),分組顯示顯示相關(guān)圖示
    # x_head_key  X軸數(shù)據(jù)列
    # comb_key 分組數(shù)據(jù)列
    # data_key 顯示數(shù)據(jù)列
    df = pd.read_csv(csv_file, sep=',', encoding='gb2312')
    cols_len = len(df.columns)
    rows_len = len(df)
    m_comb = list(set([c for c in df[comb_key]]))
    m_xhead = [str(d).strip() for d in df[(df[comb_key] == m_comb[0])][x_head_key]]
    print '數(shù)據(jù)列', cols_len, '數(shù)據(jù)行', rows_len, 'X坐標(biāo)數(shù)據(jù)', len(m_xhead)
 
    yw_list = []
    m_list = []
    m_list_head = []
 
    for i in range(len(m_comb)):
        di = [d for d in df[(df[comb_key] == m_comb[i])][data_key]]
        m_list.append(di)
        m_list_head.append(str(m_comb[i]))
    yw_i = {
        'x': m_xhead,
        'head': m_list_head,
        'data': m_list,
        'dict': m_yw
    }
    yw_list.append(yw_i)
    bars_show(yw_list)
    # lines_show(yw_list)
 
 
def an_data1():
    # 畫2張圖 : 第一季度 及 1-5月
    m_data_list = [[1,2,3],[1,2,3,4,5]]
    m_yw = {
        'title': '工作量統(tǒng)計(jì)',
        'subtitle': '',
        'width': 800,
        'height': 300
    }
    csv_data_show(r'mt_data.csv', 'S_NAME', m_data_list, m_yw)
 
 
def an_data2():
    m_yw = {
        'title': '工作量統(tǒng)計(jì)-分組',
        'subtitle': '',
        'width': 800,
        'height': 300
    }
    csv_data_show_comb(r'mc_data.csv', 'S_NAME', 'D_MONTH', 'D_DATA', m_yw)

mc_data.csv

mt_data.csv

an_data1() 的效果

以上為個(gè)人經(jīng)驗(yàn),希望能給大家一個(gè)參考,也希望大家多多支持腳本之家。

相關(guān)文章

  • 詳解使用Python寫一個(gè)向數(shù)據(jù)庫填充數(shù)據(jù)的小工具(推薦)

    詳解使用Python寫一個(gè)向數(shù)據(jù)庫填充數(shù)據(jù)的小工具(推薦)

    這篇文章主要介紹了用Python寫一個(gè)向數(shù)據(jù)庫填充數(shù)據(jù)的小工具,本文給大家介紹的非常詳細(xì),對大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下
    2020-09-09
  • 在centos7中分布式部署pyspider

    在centos7中分布式部署pyspider

    PySpider:一個(gè)國人編寫的強(qiáng)大的網(wǎng)絡(luò)爬蟲系統(tǒng)并帶有強(qiáng)大的WebUI。采用Python語言編寫,分布式架構(gòu),支持多種數(shù)據(jù)庫后端,強(qiáng)大的WebUI支持腳本編輯器,任務(wù)監(jiān)視器,項(xiàng)目管理器以及結(jié)果查看器。
    2017-05-05
  • Python的運(yùn)算符重載詳解

    Python的運(yùn)算符重載詳解

    這篇文章主要介紹了Python的運(yùn)算符重載詳解,文中有非常詳細(xì)的代碼示例,對正在學(xué)習(xí)python的小伙伴們有非常好的幫助,需要的朋友可以參考下
    2021-05-05
  • paramiko使用tail實(shí)時(shí)獲取服務(wù)器的日志輸出詳解

    paramiko使用tail實(shí)時(shí)獲取服務(wù)器的日志輸出詳解

    這篇文章主要給大家介紹了關(guān)于paramiko使用tail實(shí)時(shí)獲取服務(wù)器的日志輸出的相關(guān)資料,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧
    2020-12-12
  • Tensorflow的梯度異步更新示例

    Tensorflow的梯度異步更新示例

    今天小編就為大家分享一篇Tensorflow的梯度異步更新示例,具有很好的參考價(jià)值,希望對大家有所幫助。一起跟隨小編過來看看吧
    2020-01-01
  • tensorflow可視化Keras框架中Tensorboard使用示例

    tensorflow可視化Keras框架中Tensorboard使用示例

    這篇文章主要為大家介紹了tensorflow可視化Keras框架中Tensorboard使用示例,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪
    2022-05-05
  • 教你用python實(shí)現(xiàn)一個(gè)加密的文字處理器

    教你用python實(shí)現(xiàn)一個(gè)加密的文字處理器

    生活中有時(shí)候我們需要對一些重要的文件進(jìn)行加密,下面這篇文章主要給大家介紹了關(guān)于如何用python實(shí)現(xiàn)一個(gè)加密文字處理器的相關(guān)資料,文中通過實(shí)例代碼介紹的非常詳細(xì),需要的朋友可以參考下
    2022-06-06
  • python中超簡單的字符分割算法記錄(車牌識別、儀表識別等)

    python中超簡單的字符分割算法記錄(車牌識別、儀表識別等)

    這篇文章主要給大家介紹了關(guān)于python中超簡單的字符分割算法記錄,如車牌識別、儀表識別等,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友可以參考下
    2021-09-09
  • Pytorch四維Tensor轉(zhuǎn)圖片并保存方式(維度順序調(diào)整)

    Pytorch四維Tensor轉(zhuǎn)圖片并保存方式(維度順序調(diào)整)

    這篇文章主要介紹了Pytorch四維Tensor轉(zhuǎn)圖片并保存方式(維度順序調(diào)整),具有很好的參考價(jià)值,希望對大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教
    2022-12-12
  • python?字典常用方法超詳細(xì)梳理總結(jié)

    python?字典常用方法超詳細(xì)梳理總結(jié)

    這篇文章主要介紹了Python數(shù)據(jù)類型字典dictionary,字典是另一種可變?nèi)萜髂P?,且可存?chǔ)任意類型對象。本篇文字將詳細(xì)講述字典的常用方法,需要的可以參考一下
    2022-03-03

最新評論