Python 如何解决“问题”;属性错误:';系列';对象没有属性';查找'&引用;以x轴作为存储箱打印时出错?

Python 如何解决“问题”;属性错误:';系列';对象没有属性';查找'&引用;以x轴作为存储箱打印时出错?,python,pandas,matplotlib,plot,binning,Python,Pandas,Matplotlib,Plot,Binning,我有一个数据框,它有两列x和y,其中包含10箱其他数据框的一列及其各自的值。我试图将xs与ys进行对比,但我得到了错误: import pandas as pd import matplotlib.pyplot as plt df = pd.DataFrame(columns=['x','y']) df['x'] = ['19.0-23.0', '24.0-28.0', '29.0-33.0', '34.0-38.0', '39.0-43.0', '44.0-48.0', '49.0-53.

我有一个数据框,它有两列
x
y
,其中包含10箱其他数据框的一列及其各自的值。我试图将
x
s与
y
s进行对比,但我得到了错误:

import pandas as pd
import matplotlib.pyplot as plt

df = pd.DataFrame(columns=['x','y'])

df['x'] = ['19.0-23.0', '24.0-28.0', '29.0-33.0', '34.0-38.0', '39.0-43.0', '44.0-48.0', '49.0-53.0', '54.0-58.0', '59.0-63.0', '64.0-68.0']
df['y'] = ['0.065217', '0.039548', '0.06015', '0.054945', '0.085366', '0.071429', '0.137931', '0.129032', '0.190476', '0']

plt.plot([str(i) for i in df['x']], df['y']) 

---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
<ipython-input-28-001ebdb8bf81> in <module>()
      7 df['y'] = ['0.065217', '0.039548', '0.06015', '0.054945', '0.085366', '0.071429', '0.137931', '0.129032', '0.190476', '0']
      8 
----> 9 plt.plot([str(i) for i in df['x']], df['y'])

~\AppData\Local\Continuum\anaconda3\lib\site-packages\matplotlib\pyplot.py in plot(*args, **kwargs)
   3315                       mplDeprecation)
   3316     try:
-> 3317         ret = ax.plot(*args, **kwargs)
   3318     finally:
   3319         ax._hold = washold

~\AppData\Local\Continuum\anaconda3\lib\site-packages\matplotlib\__init__.py in inner(ax, *args, **kwargs)
   1896                     warnings.warn(msg % (label_namer, func.__name__),
   1897                                   RuntimeWarning, stacklevel=2)
-> 1898             return func(ax, *args, **kwargs)
   1899         pre_doc = inner.__doc__
   1900         if pre_doc is None:

~\AppData\Local\Continuum\anaconda3\lib\site-packages\matplotlib\axes\_axes.py in plot(self, *args, **kwargs)
   1404         kwargs = cbook.normalize_kwargs(kwargs, _alias_map)
   1405 
-> 1406         for line in self._get_lines(*args, **kwargs):
   1407             self.add_line(line)
   1408             lines.append(line)

~\AppData\Local\Continuum\anaconda3\lib\site-packages\matplotlib\axes\_base.py in _grab_next_args(self, *args, **kwargs)
    405                 return
    406             if len(remaining) <= 3:
--> 407                 for seg in self._plot_args(remaining, kwargs):
    408                     yield seg
    409                 return

~\AppData\Local\Continuum\anaconda3\lib\site-packages\matplotlib\axes\_base.py in _plot_args(self, tup, kwargs)
    355         ret = []
    356         if len(tup) > 1 and is_string_like(tup[-1]):
--> 357             linestyle, marker, color = _process_plot_format(tup[-1])
    358             tup = tup[:-1]
    359         elif len(tup) == 3:

~\AppData\Local\Continuum\anaconda3\lib\site-packages\matplotlib\axes\_base.py in _process_plot_format(fmt)
     92     # handle the multi char special cases and strip them from the
     93     # string
---> 94     if fmt.find('--') >= 0:
     95         linestyle = '--'
     96         fmt = fmt.replace('--', '')

~\AppData\Local\Continuum\anaconda3\lib\site-packages\pandas\core\generic.py in __getattr__(self, name)
   4374             if self._info_axis._can_hold_identifiers_and_holds_name(name):
   4375                 return self[name]
-> 4376             return object.__getattribute__(self, name)
   4377 
   4378     def __setattr__(self, name, value):

AttributeError: 'Series' object has no attribute 'find'

但这是一个乏味的修复,如果不是一个复杂的修复,而且这个问题甚至不应该在一开始就出现,就像在我的其他数据集中没有出现一样。那么,为什么会发生这种情况?我如何正确地修复它?

找到无法转换为浮点的字符串并打印它?如果您查看它们,显然是
df[x]
值。我不明白的是,为什么我以前从未在其他数据集上得到过这个错误,我做了完全相同的事情,现在才得到它?为什么要将垃圾箱转换为浮箱?它们是字符串,它应该像在我的其他数据集上一样按原样打印它们。
plt.plot([str(i)for i in df.x],df.y)
对我来说效果很好。问题中的代码对我来说效果很好,这意味着很可能需要更新matplotlib和pandas.hmm。但这适用于不同的数据集。我刚才又查了一遍。为什么会这样?
import pandas as pd
import matplotlib.pyplot as plt

df = pd.DataFrame(columns=['x','y'])

df['x'] = ['19.0-23.0', '24.0-28.0', '29.0-33.0', '34.0-38.0', '39.0-43.0', '44.0-48.0', '49.0-53.0', '54.0-58.0', '59.0-63.0', '64.0-68.0']
df['y'] = ['0.065217', '0.039548', '0.06015', '0.054945', '0.085366', '0.071429', '0.137931', '0.129032', '0.190476', '0']

fig, ax = plt.subplots()
plt.plot(df['y'])
labels = ['19.0-23.0', '24.0-28.0', '29.0-33.0', '34.0-38.0', '39.0-43.0', '44.0-48.0', '49.0-53.0', '54.0-58.0', '59.0-63.0', '64.0-68.0']
ax.set_xticklabels(labels)
plt.show()