Python 基于另一列(浮动)更改列(分类)值

Python 基于另一列(浮动)更改列(分类)值,python,pandas,if-statement,replace,Python,Pandas,If Statement,Replace,我尝试执行此代码以替换所有df_短线['aoh']df_短线['category'][df_短线['aoh']您可以使用以下代码来使用loc: df_-dash.loc[df_-dash['aoh']一文不值-您的np.where解决方案应该有效,但我认为您在函数调用的第二部分使用了df['category'] 看不到代码的其余部分,但假设数据帧大小不同。它的可能副本工作得很好,但您不认为使用loc也一样好吗?@YongkangZhaoloc在传递df切片函数时更好,以确保数据作为引用传递,以防

我尝试执行此代码以替换所有df_短线['aoh']
df_短线['category'][df_短线['aoh']您可以使用以下代码来使用
loc


df_-dash.loc[df_-dash['aoh']一文不值-您的
np.where
解决方案应该有效,但我认为您在函数调用的第二部分使用了
df['category']


看不到代码的其余部分,但假设数据帧大小不同。

它的可能副本工作得很好,但您不认为使用loc也一样好吗?@YongkangZhaoloc在传递df切片函数时更好,以确保数据作为引用传递,以防需要在原地修改
if df_dash['aoh'] <= 262:
   df_dash['category'] = 'standby'
df_dash['category'] = np.where(df_dash['aoh'] <= 262, 'standby', df['category'])
ValueError: operands could not be broadcast together with shapes (458,) () (4173,) 
 df_dash['category'][df_dash['aoh'] <= 262] = 'standby'

df_dash.loc[df_dash['aoh'] <= 262,'category'] = 'standby'