我有这个数据框:
V1 V2
1 1
0 0
0 0
0 0
1 0
1 1
0 1
Run Code Online (Sandbox Code Playgroud)
我需要将每个V1和V2行值与名为comienzo的变量进行比较,并在该函数后面设置名为Label的第三列:
def labeling(DataFrame):
comienzo=0 #flag to indicate event started (1= started, 0= no started)
for n in range(len(DataFrame)):
if ((DataFrame.iloc[n]['V1']==1 & DataFrame.iloc[n]['V2']==1) & comienzo == 0 ) :
comienzo=1
DataFrame['Label']='Start'
elif ((DataFrame.iloc[n]['V1']==0 & DataFrame.iloc[n]['V2']==0) & comienzo == 1 ) :
comienzo=0
DataFrame['Label']='End'
return DataFrame
Run Code Online (Sandbox Code Playgroud)
我想使用 来做到这一点Dataframe.apply。所以,我尝试了这个:
def labeling(x, comienzo):
if ((x['V1']==1 & x['V2']==1) & …Run Code Online (Sandbox Code Playgroud)