偶然发现的,完全不知道原因是什么

# 导入如下数据框
dtf = pd.DataFrame([{"A":'1992-02-04',"B":'2'},{"A":'1992-02-05',"B":'2'}])
# 直接一步将完成"字符串 -> datetime.datetime -> time.struct_time"则无报错,结果没有任何问题
dtf['D'] = dtf.apply(lambda x: atetime.datetime.strptime(x['A'],'%Y-%m-%d').timetuple(), axis=1)

错题集(求助中):在字符-日期时间-struct_time格式转换中报ValueError的有趣错误

# 但是如果按照如下分布完成,则会报错
dtf = pd.DataFrame([{"A":'1992-02-04',"B":'2'},{"A":'1992-02-05',"B":'2'}])
dtf['D'] = dtf.apply(lambda x: datetime.datetime.strptime(x['A'],'%Y-%m-%d'), axis=1)
# 此步正常,返回datetime.datetime格式的列'D'
dtf['E'] = dtf.apply(lambda x: x['D'].timetuple(), axis=1)
# 此步报错

错题集(求助中):在字符-日期时间-struct_time格式转换中报ValueError的有趣错误报错信息:

ValueError: Shape of passed values is (2, 9), indices imply (2, 3)
暂时还没有想到这是个什么问题··· 感觉和 apply 有关

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-02-09
  • 2021-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2021-09-24
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-01-20
  • 2021-06-02
  • 2021-07-22
相关资源
相似解决方案