python - pandas dtype conversion from object to string -
I have a CSV file containing some columns which are numbers and some strings are I when I myDF.dtypes
then shows me all the string columns as object
.
-
Someone asked a related question about why this is done. Is it possible to reinclude the string from the
dtype
object? -
Also, in general, there is an easy way to reuse dtype
int64
andFloat64
toint32
andfloat32
and save data size (in memory / disk)?
All strings are variable-length (which is the object
is dtype). You can series.astype ('S32')
if you want; But if you store it in a datafile or do a lot with it, then it will be done again for simplicity.
Some serial formats, e.g. HDFStore
however stores the wire on the disk as a fixed-length string.
You can series.astype (int32)
if you want and store it as a new type.
Comments
Post a Comment