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)