小编Dan*_*gen的帖子

将我的字典变成熊猫数据框

我有一个函数,它根据某些条件创建多个字典。

但是,我真的很想在收集后将 dict 转换为数据框。但我找不到一个简单的方法来做到这一点......现在我认为解决方案是将字典中的每个键乘以最内部字典中的键数,但希望有更好的方法

由于我的函数创建了 dict,如果有更好的方法,我可以以任何方式更改它。

这是我现在的字典

{'TSLA': {2011: {'negative': {'lowPrice': 185.16,
    'lowDate': '05/27/19',
    'highPrice': 365.71,
    'highDate': '12/10/18',
    'change': -0.49}},
  2012: {'negative': {'lowPrice': 185.16,
    'lowDate': '05/27/19',
    'highPrice': 365.71,
    'highDate': '12/10/18',
    'change': -0.49}},
  2013: {'negative': {'lowPrice': 32.91,
    'lowDate': '01/07/13',
    'highPrice': 37.24,
    'highDate': '03/26/12',
    'change': -0.12},
   'positive': {'lowPrice': 32.91,
    'lowDate': '01/07/13',
    'highPrice': 190.9,
    'highDate': '09/23/13',
    'change': 4.8}}}}
Run Code Online (Sandbox Code Playgroud)

我想要的输出是这样的,当然还有值:

                    lowPrice lowDate highPrice highDate change
ATVI  2012 Negative      NaN     NaN       NaN      NaN  NaN
           Positive      NaN     NaN       NaN      NaN  NaN
      2013 Negative      NaN     NaN       NaN …
Run Code Online (Sandbox Code Playgroud)

python dictionary pandas

4
推荐指数
2
解决办法
210
查看次数

标签 统计

dictionary ×1

pandas ×1

python ×1