Я не понимаю, как я могу построить xticks на моем графике.Я хочу использовать столбец «Спорт» моего фрейма данных в качестве значения xticks.
Данные на картинке.
div1['Athletes'] = pd.to_numeric(div1.Athletes.str.replace(',', ''))
ax = div1[['Sport','Athletes']].plot(kind='bar', title="Number of Athletes in Men's Individual Sports in NCAA Division 1", figsize=(15, 10), legend=True, fontsize=12)
SportList = div1['Sport'].tolist()
ax.set_xticklabels(SportList)
Ошибка:
AttributeError Traceback (most recent call last)
<ipython-input-44-4b8025d176c6> in <module>()
----> 1 div1['Athletes'] = pd.to_numeric(div1.Athletes.str.replace(',', ''))
2 ax = div1[['Sport','Athletes']].plot(kind='bar', title="Number of Athletes in Men's Individual Sports in NCAA Division 1", figsize=(15, 10), legend=True, fontsize=12)
3 SportList = div1['Sport'].tolist()
4 ax.set_xticklabels(SportList)
/opt/conda/lib/python3.5/site-packages/pandas/core/generic.py in
__getattr__(self, name)
2738 if (name in self._internal_names_set or name in self._metadata or
2739 name in self._accessors):
-> 2740 return object.__getattribute__(self, name)
2741 else:
2742 if name in self._info_axis:
/opt/conda/lib/python3.5/site-packages/pandas/core/base.py in __get__(self, instance, owner)
239 # this ensures that Series.str.<method> is well defined
240 return self.accessor_cls
--> 241 return self.construct_accessor(instance)
242
243 def __set__(self, instance, value):
/opt/conda/lib/python3.5/site-packages/pandas/core/strings.py in
_make_str_accessor(self)
1839 # (instead of test for object dtype), but that isn't practical for
1840 # performance reasons until we have a str dtype (GH 9343)
-> 1841 raise AttributeError("Can only use .str accessor with string "
1842 "values, which use np.object_ dtype in "
1843 "pandas")
AttributeError: Can only use .str accessor with string values, which use np.object_ dtype in pandas