如何修复 AttributeError:“系列"对象没有“查找"属性?

How to fix AttributeError: #39;Series#39; object has no attribute #39;find#39;?(如何修复 AttributeError:“系列对象没有“查找属性?)
本文介绍了如何修复 AttributeError:“系列"对象没有“查找"属性?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

问题描述

我正在尝试使用一些在线数据,但由于绘图函数中的属性"错误而无法绘制它

I am trying to play with some online data, and having some trouble plotting it due to an 'Attribute' error in the plot function

# Reading data from an online data sets
import pandas as pd
import requests, zipfile, StringIO
r = requests.get('https://archive.ics.uci.edu/ml/machine-learning-databases/00287/Activity Recognition from Single Chest-Mounted Accelerometer.zip')
z = zipfile.ZipFile(StringIO.StringIO(r.content))
activity_files = [name for name in z.namelist() if name.endswith('.csv')]

# Loading it to a pandas dataframe
z_data = z.read(activity_files[4]).split('
')
activity_data = pd.DataFrame([z.split(',') for z in z_data], columns=('Seq','Ax','Ay','Az','Label'))


# Filtering
working_desk_data = activity_data[activity_data.Label == '1']
standing_data = activity_data[activity_data.Label == '3']
walking_data = activity_data[activity_data.Label == '4']

# Plotting
plt.plot(walking_data['Seq'], walking_data['Ax']) # <--- Error
plt.plot(walking_data['Seq'], walking_data['Ay']) # <--- Error
plt.plot(walking_data['Seq'], walking_data['Az']) # <--- Error
plt.show()

任何解决方法或为我指出正确的方向会有帮助吗?我可以绘制以下内容,所以我显然误解了上面的内容.

Any workarounds or pointing me to the right direction would be helpful ? I can plot the following, so I am clearly misunderstanding something above.

plt.plot(range(1,5), [1,2,1,2])
plt.show()

(为 Julien Spronck 添加数据)

(Added data for Julien Spronck)

walking_data.head()
Out[12]:
Seq Ax  Ay  Az  Label
22950   22950   1978    2386    1988    4
22951   22951   1977    2387    1990    4
22952   22952   1983    2390    1994    4
22953   22953   1978    2396    1994    4
22954   22954   1980    2387    1992    4

walking_data.columns
Out[79]:
Index([u'Seq', u'Ax', u'Ay', u'Az', u'Label'], dtype='object')
In [80]:

type(walking_data.Seq)
Out[80]:
pandas.core.series.Series
In [81]:

type(walking_data.Ax)
Out[81]:
pandas.core.series.Series

推荐答案

plot 感到困惑,因为您传递的是 strings,而不是数字.如果您将它们转换为(例如)floats:

plot is getting confused because you're passing it strings, not numbers. If you convert them to (say) floats:

walking_data = walking_data.astype(float)

然后你会得到

这篇关于如何修复 AttributeError:“系列"对象没有“查找"属性?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

相关文档推荐

Seasonal Decomposition of Time Series by Loess with Python(Loess 用 Python 对时间序列进行季节性分解)
Resample a time series with the index of another time series(使用另一个时间序列的索引重新采样一个时间序列)
How can I simply calculate the rolling/moving variance of a time series in python?(如何在 python 中简单地计算时间序列的滚动/移动方差?)
Python pandas time series interpolation and regularization(Python pandas 时间序列插值和正则化)
Pandas - grouping intra day timeseries by date(Pandas - 按日期对日内时间序列进行分组)
python pandas extract unique dates from time series(python pandas从时间序列中提取唯一日期)