我有一个数据框,我正在查看与每列相关的数据类型.
当我跑:
In [23]: df.dtype.descr
Out [24]: [(u'date', '
我想将货币dtype设置为S7.我在做:
In [25]: dtype_new[-1] = (u'currency', "|S7")
In [26]: print dtype_new
Out [27]: [(u'date', '
它看起来是正确的格式.所以我试着把它放回我的df:
In [28]: df = df.astype(np.dtype(dtype_new))
我收到错误:
TypeError('data type not understood',)
我应该改变什么?谢谢.这是在我最近更新anaconda之前工作的,我不知道这个问题.谢谢.
调整:
df.dtype是
In [23]: records.dtype
Out[23]: dtype((numpy.record, [(u'date', '
如何将“0”更改为少于7个字符的字符串?
如何将最后一个dtype从“O”更改为其他类型?特别是一个少于7个字符的字符串.
最后 – 这是一个unicode问题吗?
使用Unicode:
In [38]: np.dtype([(u'date', '
...:
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
in ()
----> 1 np.dtype([(u'date', '
TypeError: data type not understood
没有Unicode:
In [39]: np.dtype([('date', '
Out[39]: dtype([('date', '