Почему ожидается, что этот код теста:
test = pd.DataFrame({'bool' :[False, True], 'int':[-1,2], 'float': [-2.5, 3.4],
'compl':np.array([1-1j, 5]),
'dt' :[pd.Timestamp('2013-01-02'), pd.Timestamp('2016-10-20')],
'td' :[pd.Timestamp('2012-03-02')- pd.Timestamp('2016-10-20'),
pd.Timestamp('2010-07-12')- pd.Timestamp('2000-11-10')]})
test.dtypes
test.select_dtypes(np.number)
Создает DataFrame с включенным столбцом TimeDelta
?
>>> bool bool
>>> int int64
>>> float float64
>>> compl complex128
>>> dt datetime64[ns]
>>> td timedelta64[ns]
>>> dtype: object
>>> int float compl td
>>> 0 -1 -2.5 (1-1j) -1693 days
>>> 1 2 3.4 (5+0j) 3531 days
EDIT:
Для кого-то (включая меня) может быть полезно следующее:
Я также нашел причину, почему это поведение было неожиданным для меня сначала. Причиной был другой способ проверить, является ли dtype
из pd.DataFrame
числовым. А именно через pd.api.types.is_numeric_dtype
:
for col in test.columns:
if pd.api.types.is_numeric_dtype(test[col]):
print (test[col].dtype)
>>> bool
>>> int64
>>> float64
>>> complex128
Который производит больше «желаемого человеком» результата.