如何检查 pandas 系列是否包含时间戳? [英] How to check if a pandas Series contains Timestamps?

查看:47
本文介绍了如何检查 pandas 系列是否包含时间戳?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

以下情况似乎至少在某些情况下有效:

Following seems to work at least in some cases:

series.dtype == np.dtype('<M8[ns]')

但是它看起来并不漂亮,我不确定它是否总是可以使用(所有(?)种类的时间戳).

but it doesn't look pretty and I'm not sure if it works always (with all(?) kinds of Timestamps).

是否有更好的方法来测试列是否包含时间戳?

Is there a nicer way for testing whether a column contains Timestamps?

推荐答案

尝试它应该起作用:

pd.core.dtypes.common.is_datetime_or_timedelta_dtype(series)

如果您通过pd.core.dtypes.common.is_,您会发现许多检查时间戳的选项.如果要合并它们,则可以使用逻辑运算符,例如:

if you go through pd.core.dtypes.common.is_ you will find many options for checking timestamps. If you want to combine them then you can use logical operators like:

pd.core.dtypes.common.is_datetime64_ns_dtype(ser)|pd.core.dtypes.common.is_timedelta64_ns_dtype(ser)

这篇关于如何检查 pandas 系列是否包含时间戳?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆