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 dtype currency on S7. I do:
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 like the correct format. Therefore, I am trying to return it to my df:
In [28]: df = df.astype(np.dtype(dtype_new))
And I get the error message:
TypeError('data type not understood',)
What should I change? Thank. This worked before I recently updated anaconda and I am not aware of this issue. Thank.
ADJUSTMENT:
df.dtype
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 to change "0" to a string less than 7 characters?
How can I change the last dtype from 'O' to something else? In particular, the string is less than 7 characters.
Is LASTLY a problem with unicode? 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')])