【发布时间】:2019-04-14 13:32:00
【问题描述】:
我尝试使用 iterrows 作为命令来处理框架。
stocks2['Startpoint']=0
for index,row in stocks2.iterrows():
if row['VOL']>4*row['avg'] and row['RET']< -0.02 :
row['Startpoint']=1
我知道条件多次满足,但在那种情况下它似乎没有成功覆盖该值。
stocks2['Startpoint'].value_counts()
输出[141]: 0 1588603 名称:起点,数据类型:int64
【问题讨论】:
-
因为
.iterows在代表数据框行的pd.Series对象上返回一个迭代器,但是改变这些pd.Series对象不会影响原始pd.DataFrame
标签: pandas loops dataframe iteration