Pandas报错no attribute 'convert_dtypes'解决办法
【摘要】 1.bug重现代码dataframe = pd.read_csv('/home/mw/input/Soviet_70yrs4904/RUStoWorldTrade.csv', usecols=['Year','Aggregate Level','Reporter ISO','Partner','Partner ISO','Commodity Code','Commodity','Qty U...
1.bug重现
代码
dataframe = pd.read_csv('/home/mw/input/Soviet_70yrs4904/RUStoWorldTrade.csv', usecols=['Year','Aggregate Level','Reporter ISO','Partner','Partner ISO','Commodity Code','Commodity','Qty Unit','Qty','Netweight (kg)','Trade Value (US$)'])
dataframe = dataframe.convert_dtypes()
报错信息
/opt/conda/lib/python3.6/site-packages/IPython/core/interactiveshell.py:3020: DtypeWarning:
Columns (11) have mixed types. Specify dtype option on import or set low_memory=False.
---------------------------------------------------------------------------
AttributeError Traceback (most recent call last)
<ipython-input-4-981831ba9217> in <module>
1 dataframe = pd.read_csv('/home/mw/input/Soviet_70yrs4904/RUStoWorldTrade.csv', usecols=['Year','Aggregate Level','Reporter ISO','Partner','Partner ISO','Commodity Code','Commodity','Qty Unit','Qty','Netweight (kg)','Trade Value (US$)'])
----> 2 dataframe = dataframe.convert_dtypes()
/opt/conda/lib/python3.6/site-packages/pandas/core/generic.py in __getattr__(self, name)
5065 if self._info_axis._can_hold_identifiers_and_holds_name(name):
5066 return self[name]
-> 5067 return object.__getattribute__(self, name)
5068
5069 def __setattr__(self, name, value):
AttributeError: 'DataFrame' object has no attribute 'convert_dtypes'
2.pandas版本查看
import pandas
pandas.__version__
‘0.24.2’
!python --version
Python 3.6.4 :: Anaconda, Inc.
显然,版本太低了。。。。。。
3.解决办法
升级python 和 pandas
出现这种情况是由于pandas 1.0.0版本只支持python3.6以上版本(不包含python3.6.0)
【版权声明】本文为华为云社区用户原创内容,转载时必须标注文章的来源(华为云社区)、文章链接、文章作者等基本信息, 否则作者和本社区有权追究责任。如果您发现本社区中有涉嫌抄袭的内容,欢迎发送邮件进行举报,并提供相关证据,一经查实,本社区将立刻删除涉嫌侵权内容,举报邮箱:
cloudbbs@huaweicloud.com
- 点赞
- 收藏
- 关注作者
评论(0)