《xls json csv 文件读取》

#coding=utf-8
import xlrd
import json
import csv

#地址前用'\'转译符要加
workbook=xlrd.open_workbook('D:/untitled/1022/date.xls')
#提取表格名称
sheets=workbook.sheet_names()
#提取第一个表格内容
worksheet=workbook.sheet_by_name((sheets[0]))

#统计有多少行
worksheet.nrows
#统计有多少列
worksheet.ncols
#遍历所以单元格
for i in range(worksheet.nrows):
    for j in range(worksheet.ncols):
        print(worksheet.cell_value(i,j),'\t',end='')
    print('')

#json load(filed)出来直接是对象
with open('D:/untitled/1022/date.json','r',encoding='utf-8') as filed:
    filedd = json.load(filed)
    print(filedd)

#csv.DictReader(fils)出来是首行对应值字典
with open('D:/untitled/1022/date.csv','r',encoding='utf-8') as fils:
    global jsonlist
    jsonlist = []
    reader=csv.DictReader(fils)
    for i in reader:
        print(i)
        #转换成字典
        print(dict(i))
        jsonlist.append(dict(i))

with open('D:/untitled/1022/date.csv','r',encoding='utf-8') as fils:
    #不能提取第一行
    reader=csv.reader(fils)
    for i in reader:
        print(i)

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

huanghong6956

你的鼓励是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值