def pandas_tdda_type(x):
dt = getattr(x, 'dtype', None)
if type(x) == str or dt == np.dtype('O'):
return 'string'
dts = str(dt)
if type(x) == bool or 'bool' in dts:
return 'bool'
if type(x) in (int, long) or 'int' in dts:
return 'int'
if type(x) == float or 'float' in dts:
return 'real'
if (type(x) == datetime.datetime or 'datetime' in dts
or type(x) == pandas_Timestamp):
return 'date'
if x is None or (not isinstance(x, pd.core.series.Series)
and pd.isnull(x)):
return 'null'
# Everything else is other, for now, including compound types,
# unicode in Python2, bytes in Python3 etc.
return 'other'
评论列表
文章目录