将行中具有字典的Pandas核心系列转换为Pandas数据框

问题描述 投票:1回答:2

我有一个名为“ series_1”的Pandas Core系列,该系列在每行中都有三个变量(“ V-Ratio”,“ Z-score”,“ P”)的字典。看起来像这样:

V1    [{'V-Ratio': 0.98, 'Z-score': -0.94, 'P': 0.17}]
V2    [{'V-Ratio': 0.97, 'Z-score': -1.34, 'P': 0.09}]
V3     [{'V-Ratio': 1.03, 'Z-score': 1.21, 'P': 0.89}]
V4     [{'V-Ratio': 1.04, 'Z-score': 1.41, 'P': 0.92}]
V5    [{'V-Ratio': 0.99, 'Z-score': -0.42, 'P': 0.34}]
V6    [{'V-Ratio': 0.96, 'Z-score': -1.72, 'P': 0.04}]
V7      [{'V-Ratio': 1.02, 'Z-score': 0.7, 'P': 0.76}]
V8    [{'V-Ratio': 0.97, 'Z-score': -1.09, 'P': 0.14}]
V9     [{'V-Ratio': 0.98, 'Z-score': -0.7, 'P': 0.24}]
V10     [{'V-Ratio': 0.76, 'Z-score': -9.31, 'P': 0.0}]
V11     [{'V-Ratio': 0.83, 'Z-score': -6.74, 'P': 0.0}]
V12    [{'V-Ratio': 0.92, 'Z-score': -3.14, 'P': 0.0}]
V13     [{'V-Ratio': 0.92, 'Z-score': -3.23, 'P': 0.0}]
V14     [{'V-Ratio': 0.87, 'Z-score': -4.99, 'P': 0.0}]
V15     [{'V-Ratio': 1.02, 'Z-score': 0.75, 'P': 0.77}]
V16       [{'V-Ratio': 0.9, 'Z-score': -3.7, 'P': 0.0}]
V17     [{'V-Ratio': 0.95, 'Z-score': -2.1, 'P': 0.02}]

我想将其转换为如下所示的Pandas Dataframe:

    V-Ratio Z-score  P
V1  0.98   -0.94    0.17
V2  0.97    1.34    0.09
V3  1.03    1.21    0.89
V4  1.04    1.41    0.92
V5  0.99   -0.42    0.34
.........................
.........................
.........................

我尝试过的内容:

  1. “” series = pd.DataFrame(series_1)“给我一个只有一列的数据框,其中的字典包含行中的变量。]​​>
  2. “ series = pd.DataFrame([series_1])”无法达到我的结果。
  3. “ series = pd.DataFrame(series_1,index = [0])”不起作用。
  4. 有人对我如何解决问题有任何线索吗?

我有一个名为“ series_1”的Pandas Core系列,该系列在每行中都有三个变量(“ V-Ratio”,“ Z-score”,“ P”)的字典。看起来像这样:V1 [{'V-Ratio':0.98,'Z-score':-0.94,'P':0 ....

python pandas dataframe series
2个回答
0
投票

请检查


0
投票

我认为主要的问题是,V1,V2,...中的每一个都是字典列表,但是每个字典中只有一个元素。理想情况下,您需要类似

© www.soinside.com 2019 - 2024. All rights reserved.