generate functionFri, 31 Mar 2023

get the absolute error between the columns "EVa" from dataframe "df1" grouped by the column "TV" and "EVb" from dataframe "df2" grouped by the column "TV" conserving the column "TV" transformed to string

#!/usr/bin/python import pandas as pd df1 = pd.DataFrame({"TV": ["A", "B", "C"], "EVa": [1, 2, 3]}) df2 = pd.DataFrame({"TV": ["A", "B", "C"], "EVb": [4, 5, 6]}) def get_EVa_EVb_abs_error(df1, df2): return df1.merge(df2, on="TV").groupby("TV").apply(lambda df: abs(df.loc[:, "EVa"] - df.loc[:, "EVb"])).reset_index() get_EVa_EVb_abs_error(df1, df2)

Questions about programming?Chat with your personal AI assistant