该楼层疑似违规已被系统折叠 隐藏此楼查看此楼
import pandas as pd
pop = {
'Nevada': {2001: 2.4, 2002: 2.9},
'Ohio': {2000: 1.5, 2001: 1.7, 2002: 3.6}
}
pd.DataFrame(pop, index=[2001, 2002, 2003])
然后爆出了如下错误
---------------------------------------------------------------------------
AttributeError Traceback (most recent call last) in ()----> 1 pd.DataFrame(pop,index=[2001,2002,2003])C:\ProgramData\Anaconda3\lib\site-packages\pandas\core\frame.py in __init__(self, data, index, columns, dtype, copy) 346 dtype=dtype, copy=copy) 347 elif isinstance(data, dict):--> 348 mgr = self._init_dict(data, index, columns, dtype=dtype) 349 elif isinstance(data, ma.MaskedArray): 350 import numpy.ma.mrecords as mrecordsC:\ProgramData\Anaconda3\lib\site-packages\pandas\core\frame.py in _init_dict(self, data, index, columns, dtype) 457 arrays = [data[k] for k in keys] 458 --> 459 return _arrays_to_mgr(arrays, data_names, index, columns, dtype=dtype) 460 461 def _init_ndarray(self, values, index, columns, dtype=None, copy=False):C:\ProgramData\Anaconda3\lib\site-packages\pandas\core\frame.py in _arrays_to_mgr(arrays, arr_names, index, columns, dtype) 7357 7358 # don't force copy because getting jammed in an ndarray anyway-> 7359 arrays = _homogenize(arrays, index, dtype) 7360 7361 # from BlockManager perspectiveC:\ProgramData\Anaconda3\lib\site-packages\pandas\core\frame.py in _homogenize(data, index, dtype) 7659 if isinstance(v, dict): 7660 if oindex is None:-> 7661 oindex = index.astype('O') 7662 7663 if isinstance(index, (DatetimeIndex, TimedeltaIndex)):AttributeError: 'list' object has no attribute 'astype'