当尝试在Pandas中插入一个字符串数组时,我收到一个错误:
aux= np.array([20161226, 20120420, 20161223,
"['SP' 'XL' 'XE' 'ZV' 'XU' 'IF' 'HG' 'ULD' 'SY']",
'(0.13633538513239282, 0.039241524027845025, 0.19564050002253786, 0.17932149608746137, 0.04480881449955045, 0.27140538761741784, 0.11998638143566892, 0.0745317087367265, 0.049137033779264705, 0.1354655614110052, 0.047562356315935896, 0.13409719319620442, 0.16651446027871206, 0.2015494117723845, 0.12190980580083927, 0.1227138437318694, 0.07720936162903032, 0.041365921325431335, 0.10598202117039587, 0.021333896275642895, 0.13515375099071364, 0.031167744618268566, 0.16452248000720907, 0.0025346628560343615, 0.23366082445832767, 0.21955066425507097, 0.21334384028853812)',
148.5, 1.0, 179.51393, 59.662210941314697, 10.526640162679591,
7.9034450470491917, 1.331905276751407, 144.33565565741154,
-7.6208523091608305, 4.7722339630126953, 7.0827960968017578,
6.5047937873380688], dtype=object)
df = pd.DataFrame(aux )
df = pd.DataFrame(aux , columns= cols_name)
我收到了这个错误:
File "/home/linux1/anaconda2/lib/python2.7/site-packages/pandas/core/frame.py", line 395, in _init_ndarray
else:
File "/home/linux1/anaconda2/lib/python2.7/site-packages/pandas/core/common.py", line 1737, in is_categorical_dtype
AttributeError: 'module' object has no attribute 'CategoricalDtype'
任何人都有一个想法,为什么熊猫不能接受字符串?
熊猫版本0.19.1
编辑: df = pd.DataFrame(aux)具有相同的错误。
编辑2: 完整错误追溯:
aux= np.array([20161226, 20120420, 20161223,
"['SP' 'XF' 'XE' 'ZV' 'XU' 'IF' 'HG' 'UGD' 'SY']",
'(0.16134294812191227, 0.011817049893372334, 0.19324546389077651, 0.16051896431371263, 0.08570541520688732, 0.28881638997021036, 0.12292119186694354, 0.09551750218918044, 0.037321669745917094, 0.08983805720513724, 0.015627684040541538, 0.14694832263730648, 0.21299264783655567, 0.15180503215839708, 0.1649218043269874, 0.13182901144843875, 0.03825600860290783, 0.015449264111713889, 0.15879226943184954, 0.030021392567183003, 0.11395448081821997, 0.11361705381859415, 0.17528906069842498, 0.0011600384418691614, 0.1767726378072394, 0.20731643509261824, 0.22597258099609385)',
'(-8733.0,)', 'optim_dec2016_1', 148.5, 1.0, 180.30199,
57.042431831359863, 10.136177122007473, 8.012155391736691,
1.2650999171161088, 146.92389269875395, -7.7429483702186941,
3.1701564788818359, 5.2207469940185547, 6.9186185621400069], dtype=object)
df = pd.DataFrame(aux )
Traceback (most recent call last):
File "<ipython-input-119-69d6ae69a243>", line 9, in <module>
df = pd.DataFrame(aux )
File "/home/linux1/anaconda2/lib/python2.7/site-packages/pandas/core/frame.py", line 255, in __init__
data = {}
File "/home/linux1/anaconda2/lib/python2.7/site-packages/pandas/core/frame.py", line 395, in _init_ndarray
else:
File "/home/linux1/anaconda2/lib/python2.7/site-packages/pandas/core/common.py", line 1737, in is_categorical_dtype
AttributeError: 'module' object has no attribute 'CategoricalDtype'