成人午夜视频全免费观看高清-秋霞福利视频一区二区三区-国产精品久久久久电影小说-亚洲不卡区三一区三区一区

python讀取excel表數(shù)據(jù)的方法-創(chuàng)新互聯(lián)

這篇文章將為大家詳細(xì)講解有關(guān)python讀取excel表數(shù)據(jù)的方法,小編覺得挺實(shí)用的,因此分享給大家做個(gè)參考,希望大家閱讀完這篇文章后可以有所收獲。

目前創(chuàng)新互聯(lián)已為數(shù)千家的企業(yè)提供了網(wǎng)站建設(shè)、域名、虛擬空間、網(wǎng)站托管運(yùn)營(yíng)、企業(yè)網(wǎng)站設(shè)計(jì)、青龍網(wǎng)站維護(hù)等服務(wù),公司將堅(jiān)持客戶導(dǎo)向、應(yīng)用為本的策略,正道將秉承"和諧、參與、激情"的文化,與客戶和合作伙伴齊心協(xié)力一起成長(zhǎng),共同發(fā)展。

python讀取excel表數(shù)據(jù)的方法:首先安裝Excel讀取數(shù)據(jù)的庫(kù)xlrd;然后獲取Excel文件的位置并且讀取進(jìn)來(lái);接著讀取指定的行和列的內(nèi)容,并將內(nèi)容存儲(chǔ)在列表中;最后運(yùn)行程序即可。

python讀取excel表數(shù)據(jù)的方法:

1、安裝Excel讀取數(shù)據(jù)的庫(kù)-----xlrd

直接pip install xlrd安裝xlrd庫(kù)

#引入Excel庫(kù)的xlrd
import xlrd

2、獲取Excel文件的位置并且讀取進(jìn)來(lái)

#導(dǎo)入需要讀取Excel表格的路徑
data = xlrd.open_workbook(r'C:\Users\NHT\Desktop\Data\\test1.xlsx')
table = data.sheets()[0]

3、讀取指定的行和列的內(nèi)容,并將內(nèi)容存儲(chǔ)在列表中(將第三列的時(shí)間格式轉(zhuǎn)換)

#創(chuàng)建一個(gè)空列表,存儲(chǔ)Excel的數(shù)據(jù)
tables = []
  
  
#將excel表格內(nèi)容導(dǎo)入到tables列表中
def import_excel(excel):
  for rown in range(excel.nrows):
   array = {'road_name':'','bus_plate':'','timeline':'','road_type':'','site':''}
   array['road_name'] = table.cell_value(rown,0)
   array['bus_plate'] = table.cell_value(rown,1)
   #將Excel表格中的時(shí)間格式轉(zhuǎn)化
   if table.cell(rown,2).ctype == 3:
     date = xldate_as_tuple(table.cell(rown,2).value,0)
     array['timeline'] = datetime.datetime(*date)
   array['road_type'] = table.cell_value(rown,3)
   array['site'] = table.cell_value(rown,4)
   tables.append(array)

4、運(yùn)行程序

if __name__ == '__main__':
  #將excel表格的內(nèi)容導(dǎo)入到列表中
  import_excel(table)
  #驗(yàn)證Excel文件存儲(chǔ)到列表中的數(shù)據(jù)
  for i in tables:
    print(i)

5、最終的運(yùn)行效果如下:

python讀取excel表數(shù)據(jù)的方法

6、完整的程序代碼:

import xlrd
from xlrd import xldate_as_tuple
import datetime
#導(dǎo)入需要讀取的第一個(gè)Excel表格的路徑
data1 = xlrd.open_workbook(r'C:\Users\NHT\Desktop\Data\\test.xlsx')
table = data1.sheets()[0]
#創(chuàng)建一個(gè)空列表,存儲(chǔ)Excel的數(shù)據(jù)
tables = []
#將excel表格內(nèi)容導(dǎo)入到tables列表中
def import_excel(excel):
  for rown in range(excel.nrows):
   array = {'road_name':'','bus_plate':'','timeline':'','road_type':'','site':''}
   array['road_name'] = table.cell_value(rown,0)
   array['bus_plate'] = table.cell_value(rown,1)
   if table.cell(rown,2).ctype == 3:
     date = xldate_as_tuple(table.cell(rown,2).value,0)
     array['timeline'] = datetime.datetime(*date)
   array['road_type'] = table.cell_value(rown,3)
   array['site'] = table.cell_value(rown,4)
   tables.append(array)
if __name__ == '__main__':
  #將excel表格的內(nèi)容導(dǎo)入到列表中
  import_excel(table)
  for i in tables:
    print(i)

關(guān)于python讀取excel表數(shù)據(jù)的方法就分享到這里了,希望以上內(nèi)容可以對(duì)大家有一定的幫助,可以學(xué)到更多知識(shí)。如果覺得文章不錯(cuò),可以把它分享出去讓更多的人看到。

分享文章:python讀取excel表數(shù)據(jù)的方法-創(chuàng)新互聯(lián)
文章轉(zhuǎn)載:http://jinyejixie.com/article32/ddsdsc.html

成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供網(wǎng)站內(nèi)鏈網(wǎng)站營(yíng)銷、動(dòng)態(tài)網(wǎng)站、軟件開發(fā)、響應(yīng)式網(wǎng)站自適應(yīng)網(wǎng)站

廣告

聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如需處理請(qǐng)聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來(lái)源: 創(chuàng)新互聯(lián)

搜索引擎優(yōu)化
顺义区| 高青县| 安吉县| 全椒县| 武鸣县| 泗阳县| 察雅县| 兖州市| 蓝山县| 驻马店市| 翁源县| 江安县| 运城市| 东乡| 苏尼特左旗| 翼城县| 仙桃市| 白河县| 松原市| 孟村| 泸州市| 南皮县| 浦城县| 封丘县| 田林县| 恩施市| 勐海县| 潼南县| 保康县| 清丰县| 新昌县| 瓦房店市| 巢湖市| 灵石县| 隆德县| 龙里县| 西充县| 顺昌县| 霍州市| 远安县| 晋州市|