我正在尝试使用日期列(balance_dt)的列(balance_am_xx),并希望diffrenet日期(balance_dt)的一些不同的balance_am_xx列。 但我创建的功能是一个错误: 导入日期时间 def f(r): 如果r ['balance_dt']> = datetime.datetime.strptime('2016-12-01','%Y-%m-%d')& r ['balance_dt']< = datetime.datetime.strptime('2016-12-30','%Y-%m-%d'): return r ['balance_am_01'] 如果r ['balance_dt']> = datetime.datetime.strptime('2017-01-01','%Y-%m-%d')& r ['balance_dt']< = datetime.datetime.strptime('2017-01-31','%Y-%m-%d'): return r ['balance_am_01'] + r ['balance_am_02'] df_obctohdfc ['花'] = df_obctohdfc.apply(f,axis = 1)