generate functionThu, 30 Mar 2023

Define "KPI" function for dataframe grouped by columns "time" and "Volts" for mean data of columns "NEVs" and "MWht", concatenating the names and values of columns grouped. Call "KPI" for "global_dataframe" as "gKPI". Define the dataframe "RdataFrame" with columns: - "absGap" - "dG1", "dG2", "dG3",etc. With "NVEI" columns. - "Id1","Id2","Id3", etc. With "NNewInd" columns. For the first 2 indexes of "RdataFrame", in the columns "dG1", "dG2", etc. Put the information of the columns: "time" and "Volt" of "gKPI" in Start a loop of 1000 "Sample" in "Samples", per each sample: - Get sub dataframe "SDFrame" componed by 10% of the indexes of "global_dataframe" choosen randomly. Store the list "Indexes" of indexes choosen transposed. - Call "KPI" for "SDFrame" as "sKPI". - Calculate absolute error, "absGap", and detailed error per "Volt" value, "detGap", between "sKPI" and "gKPI". - Store "absGap" and "detGap" in the dataframe "RdataFrame" in columns "aGap", "dG1", "dG2", "dG3",etc. - Store "Indexes" in the dataframe "RdataFrame" in the columns "Id1","Id2","Id3",etc.

def KPI(df): gKPI=pd.DataFrame() gKPI['time']=df.groupby('time')['Volt'].mean() gKPI['Volts']=df.groupby('Volts')['NEVs'].mean() gKPI['NEVs']=df.groupby('Volts')['MWht'].mean() gKPI.index=["mean of " + gKPI.index.name]*len(gKPI) gKPI=gKPI.reindex(['time','Volts','NEVs'],axis=1) return gKPI gKPI=KPI(global_dataframe) gKPI RdataFrame=pd.DataFrame(columns=['absGap']) RdataFrame['absGap']=np.NaN RdataFrame['dG1']=np.NaN RdataFrame['dG2']=np.NaN RdataFrame['dG3']=np.NaN RdataFrame

Questions about programming?Chat with your personal AI assistant