我正在尝试计算熊猫的累积总和:
我的给定数据是:input_df ['长度']和input_df ['编码器']
我想要的输出是:input_df [' desired_output_model1']和input_df [' desired_output_model2']
input_df [' desired_output_model1'] =行之间的差异,每次重置input_df [' encoder] = 0
input_df [' desired_output_model1'] = input_df [' desired_output_model1']的累积总和,每次input_df ['编码器] = 0时重置
import pandas as pd
input_df = pd.DataFrame([10., 13., 1., 0.3, 0.3, 16., 2, 0.4,13,2,0 ])
input_df.columns = ['length']
input_df['encoder'] = input_df.where(input_df['length']>0.5,0)
input_df['desired_output_model1']=pd.DataFrame([10., 3., 12., 1.0, 0.0, 16., 14., 2.0,13,11,2.0 ])
input_df['desired_output_model2']=pd.DataFrame([10., 13., 25, 26, 0.0, 16., 30, 32.0,13,24,26 ])
input_df.head(20)