Pandas 错误:重写值
我尝试使用iterrows作为处理帧的命令Pandas 错误:重写值,pandas,loops,dataframe,iteration,Pandas,Loops,Dataframe,Iteration,我尝试使用iterrows作为处理帧的命令 stocks2['Startpoint']=0 for index,row in stocks2.iterrows(): if row['VOL']>4*row['avg'] and row['RET']< -0.02 : row['Startpoint']=1 Out[141]: 0 1588603 名称:Startpoint,数据类型:int64无需循环,您可以使用 stocks2['Startpoint
stocks2['Startpoint']=0
for index,row in stocks2.iterrows():
if row['VOL']>4*row['avg'] and row['RET']< -0.02 :
row['Startpoint']=1
Out[141]:
0 1588603
名称:Startpoint,数据类型:int64无需循环,您可以使用
stocks2['Startpoint']=((stocks2['VOL']>4*stocks2['ave'])&(stocks2['RET']<0.2)).astype(int)
stocks2['Startpoint']=((stocks2['VOL']>4*stocks2['ave'])和(stocks2['RET'],因为.iterows
返回表示数据帧行的pd.Series
对象的迭代器,但对这些pd.Series
对象进行变异不会影响原始pd.DataFrame
stocks2['Startpoint']=((stocks2['VOL']>4*stocks2['ave'])&(stocks2['RET']<0.2)).astype(int)