python - python 中的日期时间抛出值错误

标签 python pandas

我正在尝试在Python中转换数据框中列的日期时间格式 原始日期 - 2018年7月16日 00:00 最终日期- 2018-08-16 00:00

results['Date1']=dt.datetime.strptime(str(results['Date']), "%d-%b-%Y %H:%M").strftime("%Y-%m-%d %H:%M")

但它给了我值(value)错误。当在语法中尝试特定字符串时,它可以工作 enter image description here

最佳答案

这应该有效:

result['Date1'] = pd.to_datetime(result['Date1'], format="%d-%b-%Y %H:%M").dt.strftime('%Y-%m-%d %H:%M')

输入:

               Date1
0  16-Jul-2018 00:00

输出:

              Date1
0  2018-07-16 00:00

关于python - python 中的日期时间抛出值错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51991156/

相关文章:

python - 将向量减去每一行数据帧

regex - 在pandas中过滤数据时获取 'Series'对象没有属性 'isnumeric'

python - 计算 pandas 数据框中的匹配组合

python - PyGitHub-错误 403 {"message": "This API returns blobs up to 1 MB in size

python - 在 Python 子进程模块中过滤掉需要终端的命令

python - 在python中找到图像中每个框的均值

python - 两个数据框,一个比另一个具有更多的列 -> 减去并合并

python - pygame.error : Failed loading libmpg123. dll:尝试访问无效地址

python - 添加零时奇怪的 numpy.sum 行为

python - 同一数据帧上的多个总和