Pd.dataframe.select_dtypes() Inculdes Timedelta Dtype
Why is it expected behavior that this test code: test = pd.DataFrame({'bool' :[False, True], 'int':[-1,2], 'float': [-2.5, 3.4], 'compl':np.array([1-1j, 5]),
Solution 1:
Because that's how it has been implemented:
np.issubdtype(np.timedelta64, np.number)
# TrueMore specifically,
np.issubdtype(np.timedelta64, np.integer)
# Truetimedelta and datetime dtypes in numpy are internally represented by integer. This makes it easy to represent in memory, and makes arithmetic on datetimes fast.
If you want to exclude these types from your checks, you can specify an exclude argument:
test.select_dtypes(include=['number'], exclude=['datetime', 'timedelta'])
intfloat compl
0 -1 -2.5 (1-1j)
123.4 (5+0j)
Solution 2:
Since numpy.timedelta is belong to numpy.number, if you only want the number numeric columns return
num= ['int16', 'int32', 'int64', 'float16', 'float32', 'float64','complex128']
test.select_dtypes(include=num)
Out[715]:
compl floatint0 (1-1j) -2.5 -11 (5+0j) 3.42
Post a Comment for "Pd.dataframe.select_dtypes() Inculdes Timedelta Dtype"