精华内容
下载资源
问答
  • 字典写入excel
    千次阅读
    2020-11-22 16:19:41

    我想将字典写入excel文件。我总是收到一些错误信息,有人能解释我该怎么办?Python将字典写入excel

    import sys

    import argparse

    import pyexcel

    import pyexcel.ext.xls

    import os

    #reading input..

    dict = {'Kalibrierwerte':

    [array_1]

    ,

    'Messwerte':

    [array_2]

    }

    book=pyexcel.get_book(adict=dict)

    book.save_as("../data/output2.xls")

    if __name__ == '__main__':

    sys.exit(main())

    当我运行这段代码,我得到这个错误:

    'File "C:\Python27\lib\site-packages\pyexcel\sources_init_.py", line 102, in _get_book raise NotImplementedError(MESSAGE_ERROR_NO_HANDLER) NotImplementedError: No suitable plugins imported or installed'

    我尝试不同的方法写的输出,但没有一个成功的。

    +1

    见代码有什么错误? –

    +0

    对于发布的代码:'文件'C:\ Python27 \ lib \ site-packages \ pyexcel \ sources \ __ init__.py“,第102行,在_get_book中 raise NotImplementedError(MESSAGE_ERROR_NO_HANDLER) NotImplementedError:没有合适的插件导入或安装' –

    更多相关内容
  • 主要为大家详细介绍了Python读取Json字典写入Excel表格的方法,具有一定的参考价值,感兴趣的小伙伴们可以参考一下
  • Openpyxl – 从字典写入excel的行和列

    千次阅读 2021-03-17 03:16:52
    Openpyxl – 从字典写入excel的行和列所以我试图做的是从字典中写入现有的Excel文件:wb = load_workbook(filename='test.xlsx') ws2 = wb.get_sheet_by_name("Blad3") tuple(ws2.iter_rows('A2:I1000')) for i in ...

    Openpyxl – 从字典写入excel的行和列

    所以我试图做的是从字典中写入现有的Excel文件:

    wb = load_workbook(filename='test.xlsx') ws2 = wb.get_sheet_by_name("Blad3") tuple(ws2.iter_rows('A2:I1000')) for i in ws2.iter_rows('A2:I1000'): print str(row[0].value) for i in Candidates: row[0].value = i['Start Location'] row[1].value = i['Distance'] row[2].value = i['End Location'] for p in Potential_candidates: row[4].value = p['Start Location'] row[5].value = p['Distance'] row[6].value = p['End Location'] for n in No_coords: row[8].value = No_coords print 'Saving to file "test.xlsx"' wb.save('test.xlsx')

    “print str(row [0] .value)”从工作表中获得正确的值,但是当我尝试设置它的值时:TypeError:'NoneType'对象没有属性' getitem '。

    错误发生在行[0] .value = i ['开始位置']

    我一直试图弄清楚为什么要么只是错过了最明显的事情,或者我完全失去了。 如果你可以读取它,你是否可以写入单元格?

    所以我想通了那个NoneType错误,显然这个列表在[0]处有一个None元素。 所以我添加了一个函数来从所有列表中删除这些元素,现在我有一个新的错误:

    TypeError:“元组”对象不支持项目分配

    所以我想出了我做错了什么,这是很多,首先,我的代码试图用整个字典,而不是第一个元素填充每一行。 其次行[0] =没有工作,因为…原因。 所以我做了一个混乱的解决scheme(但是,工程):

    def write_excel(): wb = load_workbook(filename='test.xlsx') ws = wb.get_sheet_by_name("Blad3") count = 0 for row in ws.iter_rows('A2:I500'): x = str(row[0].coordinate) x1 = str(row[1].coordinate) x2 = str(row[2].coordinate) x3 = str(row[4].coordinate) x4 = str(row[5].coordinate) x5 = str(row[6].coordinate) x6 = str(row[8].coordinate) try: Start = Candidates[count]['Start Location'] Dist = Candidates[count]['Distance'] End = Candidates[count]['End Location'] ws[x] = Start ws[x1] = Dist ws[x2] = End except IndexError: pass try: Pstart = Potential_candidates[count]['Start Location'] Pdist = Potential_candidates[count]['Distance'] Pend = Potential_candidates[count]['End Location'] ws[x3] = Pstart ws[x4] = Pdist ws[x5] = Pend except IndexError: pass try: NoCoo = No_coords[count] ws[x6] = NoCoo except IndexError: pass count=count+1 print 'Saving to file "test.xlsx"' wb.save('test.xlsx')

    我知道它可以清理很多,但它帮助我了解什么是poopoo,所以希望它可以帮助别人:)当我为整个程序创build一个更好的代码结构时,我会被清理干净。

    展开全文
  • 如何将python字典写入excel文件?

    千次阅读 2020-11-22 16:19:41
    我正在尝试将随机生成的字符串和数字的字典写入excel文件.我几乎成功但有一个小问题.我字典的结构如下:Age: 11, Names Count: 3, Names: nizbh,xyovj,clier该字典是通过文本文件获得的数据生成的.它根据年龄汇总...

    我正在尝试将随机生成的字符串和数字的字典写入excel文件.我几乎成功但有一个小问题.我字典的结构如下:

    Age: 11, Names Count: 3, Names: nizbh,xyovj,clier

    该字典是通过文本文件获得的数据生成的.它根据年龄汇总所有内容,如果两个人的年龄相同,则将它们分组到一个列表中.我正在尝试将此数据写入excel文件.到目前为止,我已经编写了这段代码.

    import xlsxwriter

    lines = []

    workbook = xlsxwriter.Workbook('demo.xlsx')

    worksheet = workbook.add_worksheet()

    with open ("input2.txt") as input_fd:

    lines = input_fd.readlines()

    age_and_names = {}

    for line in lines:

    name,age = line.strip().split(",")

    if not age in age_and_names:

    age_and_names[age]=[]

    age_and_names[age].append(name)

    print age_and_names

    for key in sorted(age_and_names):

    print "Age: {}, Names Count: {}, Names: {}".format(key, len(age_and_names[key]), ",".join(age_and_names[key]))

    row=0

    col=0

    for key in sorted(age_and_names):#.keys():

    row += 1

    worksheet.write(row, col, key)

    for item in age_and_names[key]:

    worksheet.write(row, col+1, len(age_and_names[key]))

    worksheet.write(row, col+1, item)

    row+=1

    workbook.close()

    但实际上这是做什么的(在excel文件中):

    11 nizbh

    xyovj

    clier

    我应该怎么做让它看起来像这样?

    Age Name Count Names

    11 3 nizbh, xyovj, clier

    最佳答案 问题确实存在于两个for循环中.我干涉并和他们一起玩,直到我到达答案.他们工作正常.感谢你们!

    用这个替换最后的for循环:

    for key in sorted(age_and_names):#.keys():

    row+=1

    worksheet.write(row, col, key)

    worksheet.write(row, col+1, len(age_and_names[key]))

    worksheet.write(row, col+2, ",".join(age_and_names[key]))

    展开全文
  • 解决方案 I personally recommend using Excel, I have been working on .csv files, but ended up using .xlsx. import xlsxwriter workbook = xlsxwriter.Workbook('File.xlsx') worksheet = workbook.add_...

    1586010002-jmsa.png

    I have a dictionary of dictionaries that I would like to write out to csv. my dictionary looks like:

    dict={

    object1:

    {

    time1:[value1,value2],

    time2:[value3,value4]

    },

    object2:

    {

    time1:[value5,value6],time2[value7,value8]

    }

    }

    I would like it to write out as:

    object1

    time1, value1, value2

    time2, value3, value4

    object2

    time1, value5, value6

    time2, value7, value8

    Thus far, I can only figure out how to write the key/value pairs out csv using the following code:

    writer = csv.writer(open('test.csv','wb'))

    for key, value in Dict.items():

    writer.writerow([key,value])

    So it looks like:

    objcet1,{

    time1:[value1,value2],time2:[value3,value4]

    }

    objcet2,{

    time1:[value5,value6],time2:[value7,value8]

    }

    I have tried writing just the outer keys (keys labeled object1 and object2) using

    writer = csv.writer(open('test.csv','wb'))

    for key, value in Dict.key():

    writer.writerow([key])

    but it just writes out a blank file. I think If I could figure out how to write the outer keys by themselves, I would be able to write out the csv as I want. Does anyone have any suggestions?

    解决方案

    I personally recommend using Excel, I have been working on .csv files, but ended up using .xlsx.

    import xlsxwriter

    workbook = xlsxwriter.Workbook('File.xlsx')

    worksheet = workbook.add_worksheet()

    row = 0

    col = 0

    for key in dictionary.keys():

    row += 1

    worksheet.write(row, col, key)

    for item in dictionary[key]:

    worksheet.write(row, col + 1, item)

    worksheet.write(row, col + 2, dictionary[key][item][0])

    row += 1

    workbook.close()

    And there you can change the columns and the rows increment so that you get the excel table you want to.

    You can even export it as a .csv file afterwards from Excel.

    展开全文
  • """处理Excel数据,并且写入 """ def __init__(self, sheet): """ 根据嵌套字典获取Excel的表头 :param sheet: 定义一个sheet的名称 """ self.wb = openpyxl.Workbook() self.ws = se...
  • python字典写入excel简便方法

    千次阅读 2021-10-24 21:08:22
    #for循环将data字典中的键和值分批的保存在ldata中 t = [int(x)] for a in data[x]: t.append(a) ldata.append(t) for i,p in enumerate(ldata): #将数据写入文件,i是enumerate()函数返回的序号数 for j,q in ...
  • 我有一个嵌套字典的列表,如下所示:[{'posts': {'item_1': 1,'item_2': 8,'item_3': 105,'item_4': 324,'item_5': 313, }},{'edits': {'item_1': 1,'item_2': 8,'item_3': 61,'item_4': 178,'item_5': 163}},{'...
  • 1、 功能限定: 因为是加载宏,打开Excel就能使用,所以为了防止误操作造成不必要的损失, 使用了 If ActiveSheet.Name <> "总资" Then Exit Sub 语句限定只能激活 总资表的时候才能使用此功能。 2、 计算写入列: ...
  • 作者:Ryoko源自:凹凸数据本文说明如何使用 xlsxwriter、pandas、openpyxl 三个库来实现数据写入 Excel写入后的格式如下图所示:以下为数据用例:importxlsxwriter下面开始分别介绍三种方法:1、xlsxwriterdefxw_...
  • 数字和公式写入多个工作表,支持格式设置,图像,图表,页面设置,条件格式设置,vba写入等功能,大多情况下,生成的文件和excel生成的文件100%相同,只支持单个单元格数据写入,无法读写现有的excel文件。...
  • 利用openpyxl库相关用法将字典类型的数据写入Excel中。 二、 实现代码 import openpyxl data = [{'欢迎': 4},{'马上': 1}, {'登陆': 1}] wb = openpyxl.Workbook() ws = wb.active ws.title = '测试' n=1 for each...
  • 将列表(含字典)数据写入Excel

    千次阅读 2020-11-24 04:55:00
    Excel数据写入字典cmd小测试打开cmd 转入Excel所在文件夹下再打开python,步骤如下: F:进入F盘cd 打开F盘下子目录导入所需要的库pandas df = pd.read_excel("data.xlsx")#读取Excelres = df.to_dict(orient = ...
  • 字典结果写入excel

    千次阅读 2020-04-02 12:02:48
  • 思路:先将字典格式的数据转换成数组类型 import pandas as pd dic = {"name":"张三","phone":"李四","sasnd":"wangwy"} k = [] for key in dic: print(key + ":" + dic[key]) num = [key,dic[key]] k.append(num...
  • Python读取Json字典写入Excel表格

    千次阅读 2017-09-26 15:43:26
    Python读取json字典写入Excel表格
  • ) print(len(a)) b=a[1] print(b) print(type(b)) print(b.values()) c=list(b.values()) print(type(c)) print(c) print(c[1]) # -*- coding: utf-8 -*- import geohash as geohash import xlwt # 写入excel文件的...
  • python把字典写入excel之一例

    千次阅读 2018-11-18 11:38:00
    直接上代码: # -*- coding: utf-8 -*- import xlsxwriter ...def generate_excel(expenses): workbook = xlsxwriter.Workbook('./rec_data.xlsx') worksheet = workbook.add_worksheet()...
  • 如下图,我需要做的是读取所有的温度文本,观察所有温度记录的起始时间和结束时间,并保存在一个字典里。 import os import pandas as pd #导入pandas包 path = 'D:\Project\data_rename' filelist = os.listdir...
  • Python 简短代码将字典列表写入Excel python爬虫爬取的数据一般可以方便的储存为字典列表类型,即 [{},{},{}] 而将数据保存到本地时,为了使数据美观,可以写入到Excel表格 喜欢爬虫的同学可以浏览我上一篇文章 Python...
  • 关键词:Python, 邮件扫描, yaml配置文件,邮件附件编解码,Excel自动处理一 、前言 作为一只二级市场资管狗,平时少不了向各相关方汇报产品数据,不论领导、风控部门同事、市场人员或者客户,经常会要求我们按照...
  • 大家好,我们今日讲解"VBA信息获取与处理"教程中第十六个专题"将Excel信息传递给Powerpoint及文本文件"的第四节"将txt数据信息输出到excel文件",这个专题是非常实用的知识点,希望大家能掌握利用。教程会提供配套的...
  • pip install pandas # 安装pandas pip install xlrd openpyxl # pandas 读取写入excel同样需要xlrd,openpyxl pip install jupyter # 为了方便调试,最好安装jupyter jupyter notebook # 开启jupyter notebook环境 ##...
  • python pandas 读取文件 写入文件excel

    千次阅读 2021-01-14 06:21:00
    读取数据import pandas as pd import collections def readLocationCodeForExcel(): read_file = r"test.xlsx" sheet_names = {"库位码","地堆码"} sheet_data = pd.ExcelFile(read_file) #读取sheet数据 #sheet列表...
  • #双重字典excel方法 def dict_to_excel(dict): #dict转二维列表,将字典dict的行列保存 row = dict.keys() col = list(dict.values())[0].keys() excel = [list(dict[u].values()) for u in dict] print

空空如也

空空如也

1 2 3 4 5 ... 20
收藏数 11,874
精华内容 4,749
关键字:

字典写入excel