【问题标题】:Issue with Python while converting excel into dictionary using Pandas使用 Pandas 将 excel 转换为字典时出现 Python 问题
【发布时间】:2018-05-13 22:53:53
【问题描述】:

我尝试使用 Pandas 库将 excel 文件转换为 python 中的字典,如下所示

import pandas as pd

my_dic = pd.read_excel('zoho.xlsx', index_col=0).to_dict)

当我尝试使用键值作为从字典中检索值时

print my_dic['Password']

它正在打印带有额外参数的数据

{1L: 991253376L} instead of 991253376

如何修剪那些额外的参数。

【问题讨论】:

  • 欢迎来到 Stackoverflow。如果您在 Stack Overflow 上签出 How to Ask 页面以备将来的努力会更好。伟大的问题往往会从社区提供更快、更好的答案 - 谢谢

标签: python excel pandas dictionary


【解决方案1】:

my_dic['Password'] 也是一个字典。试试my_dic['Password'][1]

举个例子:

my_dic = {"red" : "rot", "green" : "grün", "blue" : "blau", "password":{0:654651054}}

my_dic['password']
Out[27]: {0: 654651054}

my_dic['password'][0]
Out[28]: 6546510

【讨论】:

    猜你喜欢
    • 2021-03-13
    • 1970-01-01
    • 1970-01-01
    • 2018-05-23
    • 2019-06-01
    • 1970-01-01
    • 2019-01-23
    • 2015-03-19
    • 2018-09-12
    相关资源
    最近更新 更多