generate functionWed, 29 Mar 2023

Read the dataframe "global_dataframe" from a csv file in current directory called "Sum Data.csv". Define "KPI": Grouping the dataframe by column "Volt" and get mean information of columns "NEVs" and "MWhT". Execute "KPI" for "global_dataframe" as "gKPI". Calculate "NNewInd" as round the 10% of indexes of "global_dataframe". Calculate "NVEl" as number of different elements in the column "Volts" of "global_dataframe". Define the dataframe "RdataFrame" with columns: 1."absGap" 2. "dG1", "dG2", "dG3",etc. With "NVEI" columns. 3. "Id1","Id2","Id3", etc. With "NNewInd" columns. Start a loop of 1000 "Sample" in "Samples". Per each "Sample": 1. Get sub dataframe "SDFrame" componed by 10% of the indexes of "global_dataframe" choosen randomly, Store the indexes choosen transposed in the dataframe "RdataFrame" in the columns "Id1","Id2","Id3",etc. 2. Execute "KPI" for "SDFrame" as "sKPI". 3. Calculate absolute error, "absGap", and detailed error, "detGap", between "sKPI" and "gKPI". 4. Store "absGap" and "detGap" in the dataframe "RdataFrame" in columns "aGap", "dG1", "dG2", "dG3",etc.

def get_PM_ERR(path=Path.cwd(), filename="Sum Data.csv"): global_dataframe = pd.read_csv(str(path / filename)) KPI = global_dataframe.groupby(["Volt"]).agg({"NEVs": ["mean"], "MWhT": ["mean"]}) gKPI = KPI.reset_index() NNewInd = round(global_dataframe.shape[0] * 0.1) NVEI = global_dataframe["Volt"].nunique() RdataFrame = pd.DataFrame(columns=["absGap"] + ["dG" + str(i) for i in range(1, NVEI + 1)] + [ "Id" + str(i) for i in range(1, NNewInd + 1)]) Samples = range(1000) for Sample in Samples: SDFrame = global_dataframe.sample(n=NNewInd) RdataFrame.loc[Sample, ["Id"

Questions about programming?Chat with your personal AI assistant