generate functionFri, 31 Mar 2023

read the dataframe "global_dataframe" from csv file "Sum Dat.csv" get the absolute error between the columns "EVa" and "EVb" grouped by column "TV" conserving the column "TV" transformed to string

def myfunction(df, col_name_a, col_name_b, group_by): new_df = pd.DataFrame(index=df[group_by].unique()) for i in range(0, new_df.shape[0]): subset = df[group_by] == i new_df.loc[i, 'abs error'] = abs(df.loc[subset, col_name_a] - df.loc[subset, col_name_b]).sum() new_df.loc[i, group_by] = str(i) return new_df

Questions about programming?Chat with your personal AI assistant