使用 Panda AttributeError 的 Python 错误:“系列”对象没有属性

我正在学习一门复数课程来学习 Python 数据操作,但在第一个模块中出现了错误!我正在使用带有 Python 3.7 和 Pandas 1.0.1 的 Jupyter Notebooks。有人可以帮忙吗?


import pandas as pd


data = pd.read_csv('artwork_sample.csv')


data.dtypes

回报:


id                      int64

accession_number       object

artist                 object

artistRole             object

artistId                int64

title                  object

dateText               object

medium                 object

creditLine             object

year                  float64

acquisitionYear         int64

dimensions             object

width                   int64

height                  int64

depth                 float64

units                  object

inscription           float64

thumbnailCopyright    float64

thumbnailUrl           object

url                    object

dtype: object

然后


data.acquisitionYear.asType(float)

产生此错误:


---------------------------------------------------------------------------

AttributeError                            Traceback (most recent call last)

<ipython-input-19-9daf408c9065> in <module>

----> 1 data.acquisitionYear.asType(float)


C:\ProgramData\Anaconda3\lib\site-packages\pandas\core\generic.py in __getattr__(self, name)

   5272             if self._info_axis._can_hold_identifiers_and_holds_name(name):

   5273                 return self[name]

-> 5274             return object.__getattribute__(self, name)

   5275 

   5276     def __setattr__(self, name: str, value) -> None:


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


catspeake
浏览 141回答 1
1回答

jeck猫

https://pandas.pydata.org/pandas-docs/stable/reference/api/pandas.DataFrame.astype.html&nbsp;貌似是asType中的一种大写字母,我找了大写字母也没找到。
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

Python