您好, 欢迎来到 !    登录 | 注册 | | 设为首页 | 收藏本站

如何判断pandas数据框中的列是否为日期时间类型?如何判断列是否为数字?

如何判断pandas数据框中的列是否为日期时间类型?如何判断列是否为数字?

熊猫有一个很酷的功能,称为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
其他 2022/1/1 18:36:21 有406人围观

撰写回答


你尚未登录,登录后可以

和开发者交流问题的细节

关注并接收问题和回答的更新提醒

参与内容的编辑和改进,让解决方法与时俱进

请先登录

推荐问题


联系我
置顶