【问题标题】:Split Get from Python dictionary从 Python 字典中拆分获取
【发布时间】:2021-07-12 10:00:38
【问题描述】:

我有一个字典,我可以使用 get 方法从中提取值,但我需要对这些值进行子集化。例如

dict_of_measures = {k: v for k, v in measures.groupby('Measure')}

我正在使用 get

BCS=dict_of_measures.get('BCS')

我有几个值,想知道是否可以使用 for 循环使用 get 方法从字典和子集中提取每个度量的多个数据帧?这可能吗?

for measure name in dict_of_measures: 
          get measure name()

【问题讨论】:

    标签: pandas dictionary pandas-groupby


    【解决方案1】:

    你可以使用dict理解-

    result= []
    keys_to_extract = ['key1','key2']
    new_dict = {k: bigdict[k] for k in keys_to_extract}
    result.append(new_dict) # add dictionary to list. This can then be converted into pandas dataframe
    

    【讨论】:

    • 谢谢,您将使用哪个代码将 new_dict 转换为 pandas 数据帧?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2014-10-26
    • 2018-10-04
    • 1970-01-01
    • 1970-01-01
    • 2018-07-08
    • 2016-01-10
    • 1970-01-01
    相关资源
    最近更新 更多