generate functionThu, 30 Mar 2023

Define an interger variable "NVEI" with the value 128 Define an interger variable "NNewInd" with the value 16 Define the dataframe "RdataFrame" with columns: - "absGap" - "NEV1", "NEV2", "NEV3",etc. With "NVEI" columns. - "MWh1", "MWh2", "MWh3",etc. With "NVEI" columns. - "Id1","Id2","Id3", etc. With "NNewInd" columns. For the index [0] of "RdataFrame", in the columns "dG1", "dG2", etc. Put the information of the column "time" of "gKPI" 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 total error, "absGap", and detailled error "detGap" between "sKPI" and "gKPI" grouped by "time" column. - 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.

import pandas as pd import numpy as np from random import sample np.set_printoptions(formatter={'float': '{: 0.3f}'.format}) from KPI import KPI def Create_Dataframe(global_dataframe,gKPI,NVEI,NNewInd,Samples): RdataFrame=pd.DataFrame(columns=["absGap"]+["NEV%d"%i for i in range(1,NVEI+1)]+["MWh%d"%i for i in range(1,NVEI+1)]+["Id%d"%i for i in range(1,NNewInd+1)]) RdataFrame.loc[0]=[0]*NVEI*2+[0]*NNewInd for i in range(Samples): Indexes=np.array(sample(range(len(global_dataframe)),int(10*len(global_dataframe)/100))) SDFrame=global_dataframe.iloc[Indexes]

Questions about programming?Chat with your personal AI assistant