【发布时间】:2023-02-23 02:54:18
【问题描述】:
给定一个 Python 字典,我试图对键值不匹配的系列取平均值。以下是字典的示例,其中有 N 个 winner_num 键,平均值取自“value_held_graph”的每个索引。
nested_dict = {'winner_num_0': {'cash_held': 1800.546655015998,
'value_held_graph': [655.0,
657.1859489988019,
668.1170748266165,
673.4509510481149,
...
682.6094632572457
]},
'winner_num_1': {'cash_held': 2307.4282142925185,
'value_held_graph': [655.0,
643.9625087246983,
714.9614460254422,
716.9587778340948,
...
713.7097698975869
]},
'winner_num_N': {'cash_held': 2307.4282142925185,
'value_held_graph': [655.0,
654.5754236503379,
659.630701080459,
664.9212169741535,
...
654.4366560963232
]}
期望的结果如下所示:
value_held_graph_mean = [655.0, 651.9079605, 680.903074, 685.1103153, ..., 683.5852964]
【问题讨论】:
-
您忘记发布解决此问题的尝试。
-
这应该是一个简单的
for循环。 -
for循环完全没问题。并非所有东西都需要某种 pythonic one liner。
标签: python dictionary mean