考虑下表“df”:
date sales
0 2021-04-10 483
1 2022-02-03 226
2 2021-09-23 374
3 2021-10-17 186
4 2021-07-17 35
我想使用apply()and将当前为字符串的列日期转换为日期datetime.strptime()。
我尝试了以下方法:
format_date = "%Y-%m-%d"
df["date_new"] = df.loc[:,"date"].apply(datetime.strptime,df.loc[:,"date"],format_date)
我有以下错误。
系列的真值是不明确的。使用 a.empty、a.bool()、a.item()、a.any() 或 a.all()。
我尝试了不同的语法(带有args和**kwds参数,apply()但我总是收到错误),例如:
apply() 正好接受 2 个参数(给出 3 个)
有人可以帮我语法吗?谢谢你。
慕田峪9158850
相关分类