【发布时间】:2021-07-21 21:41:50
【问题描述】:
我有这样一个数据框:
ds y
22/02/18 13 1
28/07/19 14 1
09/02/21 15 2
我想将 ds 列设为日期时间并使用:
df1['ds'] = pd.to_datetime(df1['ds'], format = '%d/%m/%y %H')
但是得到:
TypeError: only integer scalar arrays can be converted to a scalar index
我必须在这里做什么?问题是,之前完全相同的操作有效,但现在不可能了。
编辑:感谢所有答案!我在我的脚本中发现了一个可能导致错误的错误。请投票结束这个问题。
【问题讨论】:
-
你能放一个更好的数据框版本吗?目前还不清楚每列的元素在哪里开始和结束。哪个是你的“ds”栏的内容,哪个是“y”栏的内容?
标签: python pandas datetime typeerror