[英]Extract data from a list in python
我有以下列表:
[N 12.000000
mean 2.011608
median 2.021611
std 0.572034
relative std 0.284350
dtype: float64,
N 12.000000
mean 2.011608
median 2.021611
std 0.571815
relative std 0.284262
dtype: float64,
N 12.000000
mean 2.011608
median 2.021611
std 0.572101
relative std 0.284412
dtype: float64,
N 12.000000
mean 2.011608
median 2.021611
std 0.572115
relative std 0.284440
dtype: float64,
N 12.000000
mean 2.011608
median 2.021611
std 0.571872
relative std 0.284313
dtype: float64]
我想從具有最小相對標准值的列表中提取數據(N、均值、標准、相對標准)。 上述列表中的output應該如下:
N 12.000000
mean 2.011608
median 2.021611
std 0.571815
relative std 0.284262
dtype: float64
到目前為止我嘗試了什么?
min(list)
但是會引發以下錯誤ValueError: The truth value of a Series is ambiguous. Use a.empty, a.bool(), a.item(), a.any() or a.all().
ValueError: The truth value of a Series is ambiguous. Use a.empty, a.bool(), a.item(), a.any() or a.all().
將min
與 lambda function 一起用於 select 的Series
值std
s1 = pd.Series([0,1,2], index=['std','min','max'])
s2 = pd.Series([4,1,2], index=['std','min','max'])
s3 = pd.Series([0.8,1,2], index=['std','min','max'])
L = [s1, s2, s3]
s = min(L, key=lambda x:x.loc['std'])
print (s)
std 0
min 1
max 2
dtype: int64
測試所有最小值:
print ([x.loc['std'] for x in L])
[0, 4, 0.8]
對於索引使用np.argmin
:
import numpy as np
print (np.argmin([x.loc['std'] for x in L]))
0
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.