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)


目录
相关文章
|
5月前
|
Python
【Python】已解决:(pandas读取DataFrame列报错)raise KeyError(key) from err KeyError: (‘name‘, ‘age‘)
【Python】已解决:(pandas读取DataFrame列报错)raise KeyError(key) from err KeyError: (‘name‘, ‘age‘)
419 0
|
5月前
|
开发者 Python
【Python】已解决:(pandas read_excel 读取Excel报错)ImportError: Pandas requires version ‘2.0.1’ or newer of ‘x
【Python】已解决:(pandas read_excel 读取Excel报错)ImportError: Pandas requires version ‘2.0.1’ or newer of ‘x
324 0
|
5月前
|
API 索引 Python
【Pandas】已完美解决:AttributeError: ‘DataFrame‘ object has no attribute ‘ix‘
【Pandas】已完美解决:AttributeError: ‘DataFrame‘ object has no attribute ‘ix‘
365 0
|
编解码 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
431 0
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.
|
Python
pandas中报错:TypeError: reduction operation ‘argmax‘ not allowed for this dtype 的解决办法
pandas中报错:TypeError: reduction operation ‘argmax‘ not allowed for this dtype 的解决办法
840 0
pandas中报错:TypeError: reduction operation ‘argmax‘ not allowed for this dtype 的解决办法
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 报错 TypeError: ‘Series‘ objects are mutable, thus they cannot be hashed
Pandas 报错 TypeError: ‘Series‘ objects are mutable, thus they cannot be hashed
AttributeError: module ‘pandas‘ has no attribute ‘Series‘
简介:AttributeError: module ‘pandas’ has no attribute 'Series’
AttributeError: module ‘pandas‘ has no attribute ‘Series‘