熊猫有一个很酷的功能,称为select_dtypes
,可以将排除或包含(或两者)作为参数。它根据dtype过滤数据帧。因此,在这种情况下,您将希望包含dtype的列np.datetime64
。要按整数过滤,您可以将[np.int64, np.int32, np.int16, np.int]
,用于float [np.float32, np.float64, np.float16, np.float]
:,仅按数字列过滤:[np.number]
。
df.select_dtypes(include=[np.datetime64])
出:
date_col
0 2017-02-01
1 2017-03-01
2 2017-04-01
3 2017-05-01
在:
df.select_dtypes(include=[np.number])
出:
col1 col2
0 1 2
1 1 2
2 1 2
3 1 2