Python 在列X值为日期时间的数据框中删除行

Python 在列X值为日期时间的数据框中删除行,python,pandas,dataframe,Python,Pandas,Dataframe,我需要删除列X值为datetime的行 我试过这个 from pandas.api.types import is_datetime64_any_dtype as is_datetime indexNames = df[is_datetime(df['Column X'])].index df.drop(indexNames, inplace=True) 但它又回来了 KeyError:错误 以下内容也不起作用(无错误) 我仍然有这样的值datetime.datetime(2016,6,29,

我需要删除列X值为datetime的行

我试过这个

from pandas.api.types import is_datetime64_any_dtype as is_datetime
indexNames = df[is_datetime(df['Column X'])].index
df.drop(indexNames, inplace=True)
但它又回来了

KeyError:错误

以下内容也不起作用(无错误)

我仍然有这样的值datetime.datetime(2016,6,29,8,24,19)

我发现了一个相关的问题,但反过来了

您知道吗?

errors='concurve'
一起使用,将非datetimelike转换为
NaN
s,因此按以下方式进行过滤:

但有时熊猫会识别一些整数,比如日期时间的
2000
,因此如果可能,更准确的是指定日期时间的格式,例如这里的
YYYY-MM-DD

df = df[pd.to_datetime(df['Column X'], errors='coerce', format='%Y-%m-%d').isna()]

谢谢,这是类似的,但恰恰相反,如何删除日期时间?这一点几乎没有改变datetimes@TTeaTie-在此处使用isna
df = df[pd.to_datetime(df['Column X'], errors='coerce').isna()]
df = df[pd.to_datetime(df['Column X'], errors='coerce', format='%Y-%m-%d').isna()]