Pandas报错no attribute 'convert_dtypes'解决办法

简介: 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 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)


目录
相关文章
|
7月前
|
编解码 Python
pandas - read_csv报错:‘utf-8‘/‘gbk‘ codec can‘t decode byte 0xb1 in position 0:invalid start byte
pandas - read_csv报错:‘utf-8‘/‘gbk‘ codec can‘t decode byte 0xb1 in position 0:invalid start byte
145 0
pandas读excel类型文件报错: xlrd.biffh.XLRDError: Excel xlsx file; not supported
pandas读excel类型文件报错: xlrd.biffh.XLRDError: Excel xlsx file; not supported
Pandas报错AttributeError: Cannot access callable attribute 'sort_values' of 'DataFrameGroupBy' objects
Pandas报错AttributeError: Cannot access callable attribute 'sort_values' of 'DataFrameGroupBy' objects
Pandas pd.merge() 报错:ValueError: You are trying to merge on int64 and object columns.
Pandas pd.merge() 报错:ValueError: You are trying to merge on int64 and object columns.
Pandas pd.merge() 报错:ValueError: You are trying to merge on int64 and object columns.
Pandas 报错 TypeError: ‘Series‘ objects are mutable, thus they cannot be hashed
Pandas 报错 TypeError: ‘Series‘ objects are mutable, thus they cannot be hashed
|
Python
pandas中报错:TypeError: reduction operation ‘argmax‘ not allowed for this dtype 的解决办法
pandas中报错:TypeError: reduction operation ‘argmax‘ not allowed for this dtype 的解决办法
729 0
pandas中报错:TypeError: reduction operation ‘argmax‘ not allowed for this dtype 的解决办法
|
Python
报错:import pandas._libs.parsers as parsers RuntimeWarning
报错:import pandas._libs.parsers as parsers RuntimeWarning
AttributeError: module ‘pandas‘ has no attribute ‘Series‘
简介:AttributeError: module ‘pandas’ has no attribute 'Series’
AttributeError: module ‘pandas‘ has no attribute ‘Series‘
|
Python
pandas.read_csv() 报错 OSError: Initializing from file failed,报错原因分析和解决方法
pandas.read_csv() 报错 OSError: Initializing from file failed,报错原因分析和解决方法
564 0
|
区块链 Python
成功解决pyinstaller打包AttributeError:type object pandas._TSObject has no attribute _reduce_cython_
成功解决pyinstaller打包AttributeError:type object pandas._TSObject has no attribute _reduce_cython_
成功解决pyinstaller打包AttributeError:type object pandas._TSObject has no attribute _reduce_cython_