generate functionWed, 29 Mar 2023

Import pandas 1. Read the dataframe called "global_dataframe" from a csv file in current directory called "Sum Data.csv". 2. Define "KPI": Grouping the dataframe by column "Volt" and get mean information of columns "NEVs" and "MWhT". 3. Execute "KPI" for "global_dataframe" as "gKPI". 4. Calculate "NNewInd" as round the 10% of indexes of "global_dataframe". 5. Calculate "NVEl" as number of different elements in the column "Volts" of "global_dataframe". 6. Define the dataframe "RdataFrame" with columns: 6.1."absGap" 6.2. "dG1", "dG2", "dG3",etc. With "NVEI" columns. 6.3. "Id1","Id2","Id3", etc. With "NNewInd" columns. 7. Start a loop of 1000 "Sample" in "Samples", per each sample: 7.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. 7.2. Execute "KPI" for "SDFrame" as "sKPI". 7.3. Calculate absolute error, "absGap", and detailed error, "detGap", between "sKPI" and "gKPI". 7.4. Store "absGap" and "detGap" in the dataframe "RdataFrame" in columns "aGap", "dG1", "dG2", "dG3",etc.

import pandas as pd def get_dataframe(dfName, fName): return pd.read_csv(fName, index_col = 0) def get_KPI(df): return df.groupby("Volt").mean() def get_RdataFrame(df, NVEl, NNewInd): RdataFrame = pd.DataFrame(columns = ["absGap"]) for i in range(NVEl): RdataFrame.insert(i+1, "dG{}".format(i), 0) for i in range(NNewInd): RdataFrame.insert(i+1, "Id{}".format(i), 0) return RdataFrame def get_sample(df, NNewInd): ind = np.random.choice(df.index, NNewInd, replace = False) return df.loc[ind] def get_error(KPI1, KPI2): absGap = np.sum

Questions about programming?Chat with your personal AI assistant