我试图创建一个pandas数据帧,从另一个数据帧迭代统计统计,它通过列(用regex过滤)。如何创建结果数据帧? 输入数据帧:
In [4]: control.head()
Out[4]:
Patient Gender Age Left-Lateral-Ventricle_NVoxels Left-Inf-Lat-
Vent_NVoxels ... supramarginal_CurvInd_lh
0 P008 M 30 9414
311 ... 7.5
1 P013 F 35 7668
85 ... 10.4
2 P018 F 27 7350
202 ... 8.0
3 P033 F 55 7548
372 ... 9.2
4 P036 F 31 8598
48 ... 8.0
[5 rows x 930 columns]
我写了一个代码来统计统计数据,但仍然坚持创建数据帧
def select_volumes(group_c,group_k):
Select_list = ["Amygdala", "Hippocampus", "Lateral-Ventricle",
"Pallidum", "Putamen", "Thalamus"]
Side = ["Left", "Right"]
for s in Side:
for struct in Select_list:
volumes_c = group_c.filter(regex="^(?=.*"+s+")(?=.*"+struct+")
(?=.*Volume)")
volumes_k = group_k.filter(regex="^(?=.*"+s+")(?=.*"+struct+")
(?=.*Volume)")
k = cohens_d(volumes_c, volumes_k)
meand = volumes_c.mean()
result_df = pd.Dataframe(
{
"Cohen's norm": some result
"Mean Value": meand
}
)
return k
函数select\u volumes提供以下结果:
Left-Amygdala_Volume_mm3 -0.29729
dtype: float64
Left-Hippocampus_Volume_mm3 0.33139
dtype: float64
Left-Lateral-Ventricle_Volume_mm3 -0.111853
dtype: float64
Left-Pallidum_Volume_mm3 0.28857
dtype: float64
Left-Putamen_Volume_mm3 0.696645
dtype: float64
Left-Thalamus-Proper_Volume_mm3 0.772492
dtype: float64
Right-Amygdala_Volume_mm3 -0.358333
dtype: float64
Right-Hippocampus_Volume_mm3 0.275668
dtype: float64
Right-Lateral-Ventricle_Volume_mm3 -0.092283
dtype: float64
Right-Pallidum_Volume_mm3 0.279258
dtype: float64
Right-Putamen_Volume_mm3 0.484879
dtype: float64
Right-Thalamus-Proper_Volume_mm3 0.809775
dtype: float64
我要左杏仁核容积。。。是值为-0.29729的行,列名为Cohen's将是每个Select\u列表的列: example, how dataframe should looks
我仍然不能真正理解如何和在哪里,但是您展示了在函数的某个地方,您能够构建一个float64系列,其中包含
Left-Amygdala_Volume_mm3
作为索引,-0.29729
作为值。我假设同时,对于相同的索引值,有meand
的值。你知道吗更确切地说,我将假设:
因为它打印为:
同时,我假设
meand
也是一个类似的序列。所以我们将访问它的值作为meand.iloc[0]
(假设值是9174.1)您应该将它们组合起来以构建行的内容:
在这个例子中我们有
row
:['Left-Amygdala_Volume_mm3', -0.29729, 9174.1]
因此,您现在需要构建一个包含这些行的大型列表:
我写信给pd.数据帧函数内部:
我调用了一个函数pd.数据帧使用:
相关问题 更多 >
编程相关推荐