I have a dataframe whose columns data types need to be mapped to python native data types.
I want to be able to get a dictionary from numpy and convert each column to it's native type.
for example:
{numpy.object_: object,
numpy.bool_: bool,
numpy.string_: str,
numpy.unicode_: unicode,
numpy.int64: int,
numpy.float64: float,
numpy.complex128: complex}
I tried both astype and pd.to_numeric, neither downcasts the column sufficiently.
df['source'] = df['source'].astype(int) returns int32, as does pd.to_numeric
Update:
Most of the comments question the wisdom for doing this. networkx reads dataframes and accepts np datatypes. However the graph cannot be written using json_dumps because of this well documented error: TypeError: Object of type 'int64' is not JSON serializable
Thanks