【问题标题】:Pyexcel, how to save into columns and how to disable to auto sort after saving?Pyexcel,如何保存到列中以及如何在保存后禁用自动排序?
【发布时间】:2020-02-27 00:33:49
【问题描述】:

我正在尝试使用 pyexcel 模块,但我没有找到任何解决我的问题的方法。

所以我将字典保存到 csv 文件中:

myDict = {'the' = '3.2', 'there' = '5.5',...}
sheet = pe.get_sheet(adict = myDict)
sheet.save_as("Word_Frequency_Stat.csv")

首先我希望将数据排序到文件中的 2 列、单词和值中,然后我想禁用自动排序,因为我的字典已经按值排序。

如果有人可以帮助我,谢谢。

【问题讨论】:

标签: python csv dictionary save pyexcel


【解决方案1】:

我成功了:

所以基本上,把我的字典转换成这样的列表:

keys = []
values = []
for key, value in s_words.items():
    keys.append(key)
    values.append(value)

然后我使用了 OrderedDict:

o_words = OrderedDict({'words': keys, 'frequency': values})

当我保存文件时:

sheet = pe.get_sheet(adict = o_words)
sheet.save_as("Word_Frequency_Stat.csv")

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2015-05-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多