gpt4 book ai didi

python - 如何使用 Python pandas 验证日期?

转载 作者:行者123 更新时间:2023-12-04 10:36:53 26 4
gpt4 key购买 nike

我的数据框由一列日期组成,这些日期不一定采用正确的格式。例如: 13/13/2020 13/10/2011 - 如果格式为 mm/dd/yyyy.

最佳答案

我建议您使用 built in functionality对于这样的事情:

pd.to_datetime(Q4_df['issdt'], infer_datetime_format=True, errors='coerce')

调音 errors参数以获得您想要的行为:
errors{‘ignore’, ‘raise’, ‘coerce’}, default ‘raise’
If ‘raise’, then invalid parsing will raise an exception.
If ‘coerce’, then invalid parsing will be set as NaT.
If ‘ignore’, then invalid parsing will return the input.

关于python - 如何使用 Python pandas 验证日期?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60133294/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com