在DataFrame上执行操作时遇到一种模糊的错误。上下文是这样的:
res2 = group.z.agg(['mean', 'std', len])
res2 = res2.drop(res2[np.isnan(res2.len)].index).drop(res2[res2.len <= 5.].index)
print(type(res2))
res2 = res2.transform(uncert)
首先,我正在这样做。印刷品给出
<class 'pandas.core.frame.DataFrame'>
到目前为止,一切都很好。现在,我在转换中调用的“ uncert”函数如下所示:
def uncert(df):
values = []
for index, row in df.iterrows():
print(row.mean, row.std)
#values.append(ufloat(row['mean'], row['std']))
#df['uval'] = Series(values, index=df.index)
return df
注释掉这两行以检查发生了什么。现在,抛出一个错误:
AttributeError Traceback (most recent call last)
<ipython-input-4-e41277533a08> in <module>()
66 res2 = res2.drop(res2[np.isnan(res2.len)].index).drop(res2[res2.len <= 5.].index)
67 print(type(res2))
---> 68 res2 = res2.transform(uncert)
69
70 print('Method 2:\n', res2, "\n\n")
.
.
.
<ipython-input-6-e41277533a08> in uncert(df)
13 def uncert(df):
14 values = []
---> 15 for index, row in df.iterrows():
16 print(row.mean, row.std)
17 #values.append(ufloat(row['mean'], row['std']))
.
.
.
AttributeError: ("'Series' object has no attribute 'iterrows'", 'occurred at index mean')
Aaa,这种情况对我来说没有意义,因为我正在对DataFrame对象执行操作。框架看起来像这样:
mean std len
(-0.001, 29.409] 2.198392 0.027809 40.0
(29.409, 75.024] 1.950194 0.008493 49.0
(78.625, 203.464] 1.766212 0.014613 145.0
(205.264, 215.468] 1.604461 0.008790 10.0
有人知道或经历过类似的事情吗?