[英]'float' object is not subscriptable. Looping and saving to csv error
I want to loop over some list object, and to save the result to .csv
file.我想遍历一些列表 object,并将结果保存到
.csv
文件中。
When I run my code:当我运行我的代码时:
for i in dfxz:
meanVal = np.mean(dfxz[i])
varianceVal = np.var(dfxz[i])
skewVal = skew(dfxz[i])
kurtVal = kurtosis(dfxz[i])
try:
csv = open('tabel.csv', 'a')
csv.write(
str(meanVal) + ',' + str(varianceVal) + ',' + str(skewVal[0]) + ',' + str(kurtVal[0]) + ',' + '1' + '\n'
)
except IOError as error:
print('failed to print', error)
csv.close()
I receive the following error message:我收到以下错误消息:
TypeError Traceback (most recent call last) <ipython-input-12-4c672d5a979c> in <module>
8 csv = open('tabel.csv', 'a')
9 csv.write(
---> 10 str(meanVal) + ',' + str(varianceVal) + ',' + str(skewVal[0]) + ',' + str(kurtVal[0]) + ',' + '1' + '\n'
11 )
12 except IOError as error:
TypeError: 'float' object is not subscriptable
I already converted my pandas.DataFrame
into int
values from float
, but with no avail.我已经将我的
pandas.DataFrame
从float
转换为int
值,但无济于事。
What do I do wrong?我做错了什么?
Here:这里:
meanVal = np.mean(dfxz[i])
varianceVal = np.var(dfxz[i])
skewVal = skew(dfxz[i])
kurtVal = kurtosis(dfxz[i])
you extract the values from the list, and here:您从列表中提取值,在这里:
... str(skewVal[0]) ...
and here:和这里:
... str(kurtVal[0]) ...
you try to extract a value in the position 0
from value, so you receive the aforementioned exception.您尝试从值中提取 position
0
中的值,因此您收到上述异常。
Cheers.干杯。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.