I have a dataframe that I am looking at the data types associated with each column.
When I run:
In [23]: df.dtype.descr
Out [24]: [(u'date', '<i8'), (u'open', '<f8'), (u'high', '<f8'), (u'low', '<f8'), (u'close', '<f8'), (u'volume', '<f8'), (u'dividend', '<f8'), (u'adj_factor', '<f8'), (u'split_factor', '<f8'), (u'liq', '<f8'), (u'currency', '|O')]
I want to set the currency dtype to S7. I am doing:
In [25]: dtype_new[-1] = (u'currency', "|S7")
In [26]: print dtype_new
Out [27]: [(u'date', '<i8'), (u'open', '<f8'), (u'high', '<f8'), (u'low', '<f8'), (u'close', '<f8'), (u'volume', '<f8'), (u'dividend', '<f8'), (u'adj_factor', '<f8'), (u'split_factor', '<f8'), (u'liq', '<f8'), (u'currency', '|S7')]
It looks to be the correct format. So I try to put it back to my df:
In [28]: df = df.astype(np.dtype(dtype_new))
And I get the error:
TypeError('data type not understood',)
What should I be changing? Thank you. This was working before I recently updated anaconda and I am not aware of the issue. Thanks.
ADJUSTMENT:
df.dtype is
In [23]: records.dtype
Out[23]: dtype((numpy.record, [(u'date', '<i8'), (u'open', '<f8'), (u'high', '<f8'), (u'low', '<f8'), (u'close', '<f8'), (u'volume', '<f8'), (u'dividend', '<f8'), (u'adj_factor', '<f8'), (u'split_factor', '<f8'), (u'liq', '<f8'), (u'currency', 'O')]))
How can I change the '0' to a string less than 7 characters?
How can I change the last dtype from 'O' to something else? Specifically a string less than 7 characters.
LASTLY - is this a unicode issue? With Unicode:
In [38]: np.dtype([(u'date', '<i8')])
...:
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
<ipython-input-38-8702f0c7681f> in <module>()
----> 1 np.dtype([(u'date', '<i8')])
TypeError: data type not understood
No Unicode:
In [39]: np.dtype([('date', '<i8')])
Out[39]: dtype([('date', '<i8')])