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

python讀取excel數(shù)據(jù)并且畫(huà)圖的實(shí)現(xiàn)示例

 更新時(shí)間:2021年02月08日 11:40:03   作者:TR_Goldfish  
這篇文章主要介紹了python讀取excel數(shù)據(jù)并且畫(huà)圖的實(shí)現(xiàn)示例,幫助大家更好的理解和使用python,感興趣的朋友可以了解下

一,要讀取的數(shù)據(jù)的格式:

二,數(shù)據(jù)讀取部分:

b站視頻參考:https://www.bilibili.com/video/BV14C4y1W7Nj?t=148

# 1930
workbook=xlrd.open_workbook('1930.xlsx')
sheet= workbook.sheet_by_index(0)
A1=[]
B1=[]
# sheet.cell_value(i,0):第i行的第0個(gè)元素
for i in range(1,sheet.nrows):
 A1.append(sheet.cell_value(i,0))
 B1.append(sheet.cell_value(i,1))
 
if len(A1)!=len(B1):
 print("False")
drawBar(A1,B1,1930)
 

三,畫(huà)圖函數(shù)

1. def drawBar(Music_genre,singer_num,year)

參數(shù)介紹

參數(shù)名 參數(shù)含義
Music_genre 音樂(lè)流派名稱list
singer_num 音樂(lè)流派對(duì)應(yīng)音樂(lè)家數(shù)量list
year 讀的文件的年份(因?yàn)樵创a是從1840到2020的)

def drawBar(Music_genre,singer_num,year):
 arr_len=len(Music_genre)
 # 由循環(huán)得到一個(gè)字典,key是音樂(lè)流派,value是這個(gè)音樂(lè)流派對(duì)應(yīng)的音樂(lè)家的數(shù)量
 i=0
 dict_music_singer={}
 while i<arr_len:
 dict_music_singer[Music_genre[i]]=singer_num[i]
 i=i+1
 
	# 注釋1
 pyplot.bar(x=0, bottom=range(arr_len), height=0.3, width=singer_num, orientation="horizontal")
 # 注釋2
 pyplot.yticks(range(arr_len),Music_genre)
 # 加title,展示圖像
 pyplot.title(year)
 pyplot.show()
 
 ...
 ...
 drawBar(A1,B1,1930)
 

注釋1:

"""
 水平條形圖,需要修改以下屬性
 orientation="horizontal"
"""
import numpy as np
import matplotlib.pyplot as plt
 
# 數(shù)據(jù)
N = 5
x = [20, 10, 30, 25, 15]
y = [0,1,2,3,4]
 
# 繪圖 x= 起始位置, bottom= 水平條的底部(左側(cè)), y軸, height 水平條的寬度, width 水平條的長(zhǎng)度
p1 = plt.bar(x=0, bottom=y, height=0.5, width=x, orientation="horizontal")
pyplot.bar(range(arr_len),singer_num,align='center')
pyplot.bar(x=0, bottom=range(arr_len), height=0.5, width=singer_num, orientation="horizontal")
# 展示圖形
plt.show()

注釋2:plt.xticks的第一個(gè)參數(shù)和plt.plot的第一個(gè)參數(shù)一樣,第二個(gè)參數(shù)是和第一個(gè)參數(shù)相同長(zhǎng)度的list此例中用來(lái)代替橫坐標(biāo)

import matplotlib.pyplot as plt
x = [1, 2, 3, 4]
y = [1, 4, 9, 6]
labels = ['Frogs', 'Hogs', 'Bogs', 'Slogs']
 
plt.plot(x, y)
# You can specify a rotation for the tick labels in degrees or with keywords.
plt.xticks(x, labels, rotation='vertical')
# Pad margins so that markers don't get clipped by the axes
plt.margins(0.2)
# Tweak spacing to prevent clipping of tick-labels
plt.subplots_adjust(bottom=0.15)
plt.show()

1.1 效果:

1.2 完整代碼

import pandas as pd
import numpy as np 
import xlrd
from matplotlib import pyplot
def drawBar(Music_genre,singer_num,year):
 arr_len=len(Music_genre)
 
 i=0
 dict_music_singer={}
 while i<arr_len:
 dict_music_singer[Music_genre[i]]=singer_num[i]
 i=i+1
 #pyplot.bar(range(arr_len),singer_num,align='center')
 pyplot.bar(x=0, bottom=range(arr_len), height=0.3, width=singer_num, orientation="horizontal")
 pyplot.yticks(range(arr_len),Music_genre)
 pyplot.title(year)
 pyplot.show()
 
 
# 1930
workbook=xlrd.open_workbook('1930.xlsx')
sheet= workbook.sheet_by_index(0)
A1=[]
B1=[]
for i in range(1,sheet.nrows):
 A1.append(sheet.cell_value(i,0))
 B1.append(sheet.cell_value(i,1))
 
if len(A1)!=len(B1):
 print("False")
drawBar(A1,B1,1930)
 
 
 
# 1940
workbook=xlrd.open_workbook('1940.xlsx')
sheet= workbook.sheet_by_index(0)
A2=[]
B2=[]
for i in range(1,sheet.nrows):
 A2.append(sheet.cell_value(i,0))
 B2.append(sheet.cell_value(i,1))
 
if len(A2)!=len(B2):
 print("False")
drawBar(A2,B2,1940)
 
 
 
# 
workbook=xlrd.open_workbook('1950.xlsx')
sheet= workbook.sheet_by_index(0)
A3=[]
B3=[]
for i in range(1,sheet.nrows):
 A3.append(sheet.cell_value(i,0))
 B3.append(sheet.cell_value(i,1))
 
if len(A3)!=len(B3):
 print("False")
drawBar(A3,B3,1950)
 
 
 
# 6
workbook=xlrd.open_workbook('1960.xlsx')
sheet= workbook.sheet_by_index(0)
A4=[]
B4=[]
for i in range(1,sheet.nrows):
 A4.append(sheet.cell_value(i,0))
 B4.append(sheet.cell_value(i,1))
 
if len(A4)!=len(B4):
 print("False")
drawBar(A4,B4,1960)
 
 
 
 
# 
workbook=xlrd.open_workbook('1970.xlsx')
sheet= workbook.sheet_by_index(0)
A5=[]
B5=[]
for i in range(1,sheet.nrows):
 A5.append(sheet.cell_value(i,0))
 B5.append(sheet.cell_value(i,1))
 
if len(A5)!=len(B5):
 print("False")
drawBar(A5,B5,1970)
 
 
 
 
# 
workbook=xlrd.open_workbook('1980.xlsx')
sheet= workbook.sheet_by_index(0)
A6=[]
B6=[]
for i in range(1,sheet.nrows):
 A6.append(sheet.cell_value(i,0))
 B6.append(sheet.cell_value(i,1))
 
if len(A6)!=len(B6):
 print("False")
drawBar(A6,B6,1980)
 
 
 
 
# 9
workbook=xlrd.open_workbook('1990.xlsx')
sheet= workbook.sheet_by_index(0)
A7=[]
B7=[]
for i in range(1,sheet.nrows):
 A7.append(sheet.cell_value(i,0))
 B7.append(sheet.cell_value(i,1))
 
if len(A7)!=len(B7):
 print("False")
drawBar(A7,B7,1990)
 
 
 
 
# 2000
workbook=xlrd.open_workbook('2000.xlsx')
sheet= workbook.sheet_by_index(0)
A8=[]
B8=[]
for i in range(1,sheet.nrows):
 A8.append(sheet.cell_value(i,0))
 B8.append(sheet.cell_value(i,1))
 
if len(A8)!=len(B8):
 print("False")
drawBar(A8,B8,2000)
 
 
 
 
# 
workbook=xlrd.open_workbook('2010.xlsx')
sheet= workbook.sheet_by_index(0)
A9=[]
B9=[]
for i in range(1,sheet.nrows):
 A9.append(sheet.cell_value(i,0))
 B9.append(sheet.cell_value(i,1))
 
if len(A9)!=len(B9):
 print("False")
drawBar(A9,B9,2010)
 
 
 
 
# # 
# workbook=xlrd.open_workbook('2020.xlsx')
# sheet= workbook.sheet_by_index(0)
# A2=[]
# B2=[]
# for i in range(1,sheet.nrows):
# A2.append(sheet.cell_value(i,0))
# B2.append(sheet.cell_value(i,1))
 
# if len(A2)!=len(B2):
# print("False")
# drawBar(A2,B2,2020)
 
 
 
 
 
 

以上就是python讀取excel數(shù)據(jù)并且畫(huà)圖的實(shí)現(xiàn)示例的詳細(xì)內(nèi)容,更多關(guān)于python讀取excel數(shù)據(jù)并且畫(huà)圖的資料請(qǐng)關(guān)注腳本之家其它相關(guān)文章!

相關(guān)文章

  • 詳解Python列表解析式的使用方法

    詳解Python列表解析式的使用方法

    Python?是一種極其多樣化和強(qiáng)大的編程語(yǔ)言!當(dāng)需要解決一個(gè)問(wèn)題時(shí),它有著不同的方法。本文將將會(huì)展示列表解析式的使用方法,需要的可以參考一下
    2022-04-04
  • Python連接mysql方法及常用參數(shù)

    Python連接mysql方法及常用參數(shù)

    這篇文章主要介紹了Python連接mysql方法及常用參數(shù),文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友可以參考下
    2020-09-09
  • Python+Selenium實(shí)現(xiàn)一鍵摸魚(yú)&采集數(shù)據(jù)

    Python+Selenium實(shí)現(xiàn)一鍵摸魚(yú)&采集數(shù)據(jù)

    將Selenium程序編寫(xiě)為 .bat 可執(zhí)行文件,從此一鍵啟動(dòng)封裝好的Selenium程序,省時(shí)省力還可以復(fù)用,豈不美哉。所以本文將利用Selenium實(shí)現(xiàn)一鍵摸魚(yú)&一鍵采集數(shù)據(jù),需要的可以參考一下
    2022-08-08
  • python簡(jiǎn)單讀取大文件的方法

    python簡(jiǎn)單讀取大文件的方法

    這篇文章主要介紹了python簡(jiǎn)單讀取大文件的方法,通過(guò)非常簡(jiǎn)單的方式實(shí)現(xiàn)對(duì)GB級(jí)別大文件的讀取功能,并給出了外文參考站點(diǎn)stackoverflow的參考地址,需要的朋友可以參考下
    2016-07-07
  • python Tkinter版學(xué)生管理系統(tǒng)

    python Tkinter版學(xué)生管理系統(tǒng)

    這篇文章主要為大家詳細(xì)介紹了python Tkinter版學(xué)生管理系統(tǒng),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2019-02-02
  • python爬蟲(chóng)使用scrapy注意事項(xiàng)

    python爬蟲(chóng)使用scrapy注意事項(xiàng)

    在本篇文章里小編給大家整理的是一篇關(guān)于python爬蟲(chóng)使用scrapy注意事項(xiàng)的相關(guān)文章,對(duì)此有興趣的朋友們可以學(xué)習(xí)下。
    2020-11-11
  • Python利用matplotlib實(shí)現(xiàn)制作動(dòng)態(tài)條形圖

    Python利用matplotlib實(shí)現(xiàn)制作動(dòng)態(tài)條形圖

    說(shuō)到用 Python 制作動(dòng)態(tài)圖,首先想到的肯定是一些直接拿來(lái)就用的庫(kù),雖然我沒(méi)做過(guò),但是我相信一定有且不止一個(gè),搜了一圈后發(fā)現(xiàn)有個(gè)bar chart race庫(kù)看起來(lái)不錯(cuò),感興趣的可以跟隨小編一起學(xué)習(xí)一下
    2022-10-10
  • Python爬取微信小程序Charles實(shí)現(xiàn)過(guò)程圖解

    Python爬取微信小程序Charles實(shí)現(xiàn)過(guò)程圖解

    這篇文章主要介紹了Python爬取微信小程序Charles實(shí)現(xiàn)過(guò)程圖解,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友可以參考下
    2020-09-09
  • 詳解django2中關(guān)于時(shí)間處理策略

    詳解django2中關(guān)于時(shí)間處理策略

    這篇文章主要介紹了詳解django2中關(guān)于時(shí)間處理策略,小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過(guò)來(lái)看看吧
    2019-03-03
  • Python垃圾回收是怎么實(shí)現(xiàn)的

    Python垃圾回收是怎么實(shí)現(xiàn)的

    垃圾回收大家應(yīng)該多多少少都了解過(guò),本文詳細(xì)的介紹了Python垃圾回收是怎么實(shí)現(xiàn)的,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2021-07-07

最新評(píng)論

浦东新区| 榆社县| 昌江| 长泰县| 临泉县| 满城县| 河池市| 三江| 思南县| 永州市| 耿马| 漳浦县| 瓮安县| 绥中县| 万安县| 六盘水市| 通州区| 汤阴县| 吴堡县| 淮安市| 鹤山市| 双桥区| 渭源县| 旅游| 科技| 大石桥市| 铁岭市| 建平县| 井陉县| 通州区| 旬邑县| 岳普湖县| 石楼县| 台北市| 河曲县| 德令哈市| 甘德县| 台南市| 临湘市| 北宁市| 广西|