zoukankan      html  css  js  c++  java
  • 《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)
  • 相关阅读:
    Codeforces Canda Cup 2016
    Codeforces Round #377(div 2)
    后缀数组专题
    Codeforces Round #375(div 2)
    Codeforces Round #374(div 2)
    [HDU5902]GCD is Funny(xjb搞)
    [HDU5904]LCIS(DP)
    HDU 1251统计难题
    POJ2104 K-TH NUMBER 传说中的主席树
    poj 3041
  • 原文地址:https://www.cnblogs.com/huazhou695/p/9885810.html
Copyright © 2011-2022 走看看