我在python中使用if条件来执行计算,但是我得到的是一个系列的真值是模棱两可的。使用a.empty、a.bool()、a.item()、a.any()或a.all()。错误
如果其他列的条件是,那么有人能帮助我理解如何在基于的数据文件上执行操作吗?
if (simulated_hour['Weeknnd'] == 'Weekday'):
simulated_hour['simulated'] = simulated_hour['Forecast_call']*simulation_weekday
simulated_hour附件是代码和错误的图像。

发布于 2021-01-17 21:51:39
您可以使用以下代码片段实现您想要的结果:
simulated_hour.loc[simulated_hour['Weeknnd'] == 'Weekday', 'simulated'] = simulated_hour.loc[simulated_hour['Weeknnd'] == 'Weekday', 'Forecast_call']*simulation_weekday熊猫有自己的查询语法,因为你不能像你提到的那样使用简单的if语句进行选择。
如果您熟悉SQL,下面的状态可能有助于理解基础:https://pandas.pydata.org/docs/getting_started/comparison/comparison_with_sql.html
https://stackoverflow.com/questions/65766310
复制相似问题