我尝试执行此代码来替换所有的df\u dash['aoh']<=262转待命
if df_dash['aoh'] <= 262:
df_dash['category'] = 'standby'
然而,我得到这个错误,我似乎找不到一个方法来获得正确的结果
Traceback (most recent call last):
File "<input>", line 1, in <module>
File "/Users/jacob/anaconda3/envs/MERS/lib/python3.7/site-packages/pandas/core/generic.py", line 1555, in __nonzero__
self.__class__.__name__
ValueError: The truth value of a Series is ambiguous. Use a.empty, a.bool(), a.item(), a.any() or a.all().
我在其他线程中读到过这个错误,但是我似乎找不到解决这个特定问题的方法
我也试过用这个
df_dash['category'] = np.where(df_dash['aoh'] <= 262, 'standby', df['category'])
但是,我明白了
ValueError: operands could not be broadcast together with shapes (458,) () (4173,)
希望有人能帮忙
一文不值-您的
np.where
解决方案本应有效,但我认为您在函数调用的第二部分使用了df['category']
,而不是df_dash['category']
看不到其余的代码,但假设数据帧的大小不同
可以将
loc
与boolean indexing一起使用:相关问题 更多 >
编程相关推荐