从 python 中的列表中提取数据
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、平均值、标准值、相对标准值)。上面列表的输出应该是这样的:
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().
将 min
与 lambda 函数一起用于标签 std
的 Series
的 select 值:
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
我有以下列表:
[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、平均值、标准值、相对标准值)。上面列表的输出应该是这样的:
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().
将 min
与 lambda 函数一起用于标签 std
的 Series
的 select 值:
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