Carlos Wyller Villanueva Machado

All generations.

generate functionFri, 31 Mar 2023

giving a list "VInd"=[0.95,0.97,0.99,1.01,1.03,1.05]. Read the dataframe "global_dataframe" from "Sum Data.csv" csv file. Group "global_dataframe" by the column "Volt" with the mean value of columns "NEVs" and "MWhT" in the dataframe "SumDF". Complete the index "Volt" in "SumDF" with the information from "VInd" filling the abscent information in the columns "NEVs" and "MWhT" with the value of 0.

### --- Function to group by Volt and calculate the NEVs and MWhT over the whole period --- def NEVs_MWhT_by_Volt(VInd, global_dataframe): SumDF = pd.DataFrame(np.NaN, columns= ['NEVs','MWhT'], index= VInd) Volt_grouping = global_dataframe.groupby('Volt') SumDF.NEVs = Volt_grouping['NEVs'].mean() SumDF.MWhT = Volt_grouping['MWhT'].mean() return SumDF NEVs_MWhT_by_Volt(VInd, global_dataframe)

Python
View
generate functionWed, 29 Mar 2023

Read the dataframe called "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". Call "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: - "absGap" - "dG1", "dG2", "dG3",etc. With "NVEI" columns. - "Id1","Id2","Id3", etc. With "NNewInd" columns. 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, "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.

global_dataframe = pd.read_csv("Sum Data.csv", low_memory=False) KPI = lambda x : x.groupby(['Volt'])['NEVs','MWhT'].mean() gKPI = KPI(global_dataframe) NNewInd = int(len(global_dataframe)*0.1) NVEI = len(global_dataframe['Volt'].unique()) 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)]) for i in range(0,1000): SDFrame = global_dataframe.sample(n=NNewInd) Indexes = SDFrame.index.tolist() sKPI = KPI(SDFrame) absGap = np.abs(sKPI-gKPI).sum().sum()

Python
View
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" - "dG1", "dG2", "dG3",etc. With "NVEI" columns. - "Id1","Id2","Id3", etc. With "NNewInd" columns. For the first index 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 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.

NVEI = 128 NNewInd = 16 RdataFrame = pd.DataFrame(columns=["absGap"] + ["dG" + str(i) for i in list(range(1,NVEI+1))] + ["Id" + str(i) for i in list(range(1,NNewInd+1))]) RdataFrame.loc[0] = [0] + [0]*NVEI + [0]*NNewInd for i in range(1,NVEI+1): RdataFrame.loc[0,"dG" + str(i)] = gKPI.loc[:,"time"][i] Samples = 1000 for i in range(Samples): SDFrame = global_dataframe.sample(frac = 0.1, random_state = i) sKPI = KPI(SDFrame) absGap = abs(gKPI.loc[:,"mean"][0] - sKPI.loc[:,"mean"][0]) detGap = [

Python
View
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.

def Global_Dataframe(): import pandas global_dataframe = pandas.read_csv("Sum Data.csv") KPI = global_dataframe.groupby("Volt")[["NEVs", "MWhT"]].mean() gKPI = KPI.transpose() NNewInd = round(0.1*len(global_dataframe.index)) NVEl = global_dataframe.Volt.nunique() RdataFrame = pandas.DataFrame(columns=["absGap"]+["dG"+str(i+1) for i in range(NVEl)]) RdataFrame["Id" + str(i+1) for i in range(NNewInd)] = None for Sample in range(1000): SDFrame = global_dataframe.sample(frac=0.1) RdataFrame.loc[Sample,["Id"+str(i+1) for i in range(NNewInd)]] = SDFrame.index.values.transpose()

Python
View
generate functionThu, 30 Mar 2023

Define the dataframe "RdataFrame" with columns: - "absGap" - "dG1", "dG2", "dG3",etc. With "NVEI" columns. - "Id1","Id2","Id3", etc. With "NNewInd" columns. For the first index 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 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 RFrame(global_dataframe, NVEI, Sample, NNewInd): RdataFrame = pd.DataFrame(columns=['absGap', 'dG1', 'dG2', 'dG3', 'dG4']) gKPI = KPI(global_dataframe) l = 0 for i in range(Sample): SDFrame = global_dataframe.sample(frac = 0.1) sKPI = KPI(SDFrame) Indexes = SDFrame.index.values.reshape(1,len(SDFrame.index.values)) absGap = abs(gKPI['time'] - sKPI['time']) detGap = gKPI['time'] - sKPI['time'] RdataFrame.loc[i] = [absGap] + [detGap[k] for k in range(NVEI)] RdataFrame.loc[i] = RdataFrame.loc[i].append(pd.Series(Indexes.transpose(),

Python
View
generate functionThu, 30 Mar 2023

Define an interger variable "NVEI" Define an interger variable "NNewInd" Define the dataframe "RdataFrame" with columns: - "absGap" - "dG1", "dG2", "dG3",etc. With "NVEI" columns. - "Id1","Id2","Id3", etc. With "NNewInd" columns. For the first index 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 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.

NVEI = 4 NNewInd=2 RdataFrame=pd.DataFrame( {"absGap":[np.nan]*1000, "dG1":[np.nan]*1000, "dG2":[np.nan]*1000, "dG3":[np.nan]*1000, "dG4":[np.nan]*1000, "Id1":[np.nan]*1000, "Id2":[np.nan]*1000, "Id3":[np.nan]*1000, "Id4":[np.nan]*1000, } ) RdataFrame.loc[0,"dG1"]=gKPI.loc["time",1] for i in range(1000): SDFrame = global_dataframe.sample(frac=0.1) sKPI=KPI(SDFrame) absGap=abs(sKPI.loc["time",1]-gKPI.loc["time",1]) detGap=np.array(

Python
View
generate functionWed, 29 Mar 2023

Read the dataframe called "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". Call "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 "Volt" of "global_dataframe". Define the dataframe "RdataFrame" with columns: - "absGap" - "dG1", "dG2", "dG3",etc. With "NVEI" columns. - "Id1","Id2","Id3", etc. With "NNewInd" columns. 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.

global_dataframe = pd.read_csv('Sum Data.csv') def KPI(df): KPI = df.groupby('Volt').agg({'NEVs': 'mean', 'MWhT': 'mean'}) KPI = KPI.reset_index() return KPI gKPI = KPI(global_dataframe) NNewInd = round(len(global_dataframe)*0.1) NVEl = len(global_dataframe.Volt.unique()) RdataFrame = pd.DataFrame(columns= ['aGap'] + ['dG' + str(i) for i in range(1, NVEl+1)] + ['Id' + str(i) for i in range(1, NNewInd+1)]) Samples = 1000 for Sample in range(Samples): SDFrame = global_dataframe.sample(NNewInd) sKPI = KPI(SDFrame) Indexes = SDFrame.index.values.reshape(1

Python
View
generate functionThu, 30 Mar 2023

Read the dataframe called "global_dataframe" from a csv file in current directory called "Sum Data.csv". Define "KPI": Grouping the dataframe by columns: "time" and "Volt" and get mean information of columns "NEVs" and "MWhT". Calculate "NtVEl" as number of different elements of dataframe grouped by the columns "time" and "Volt" of "global_dataframe". Call "KPI" for "global_dataframe" as "gKPI". Calculate "NNewInd" as round the 10% of indexes of "global_dataframe". 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.

from pandas import read_csv from pandas import DataFrame from pandas import concat from pandas import Series import pandas as pd import numpy as np from numpy import mean from numpy import std from numpy import where from numpy import array from numpy import random import math from math import floor from math import sqrt from math import pow from math import isnan from random import sample def KPI(df): df = df.groupby(['time','Volt'])['NEVs','MWhT'].mean() NVEI = len(set(df.index.labels[1])) return df,NVEI global_dataframe = read_csv('Sum Data.csv') gKPI,NVEI = KPI(global_dataframe) NNewInd = floor(len(global_dataframe)*0.1) RdataFrame = DataFrame(columns=['absGap']+['dG'+str(i) for i in range(1,N

Python
View
generate functionWed, 29 Mar 2023

1. Read the dataframe "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.

def run(n): global_dataframe = pd.read_csv("Sum Data.csv") KPI = global_dataframe.groupby("Volt").agg({"NEVs": np.mean, "MWhT": np.mean}) gKPI = KPI.agg(np.mean) NNewInd = round(len(global_dataframe) * 0.1) NVEI = len(global_dataframe["Volt"].unique()) RdataFrame= pd.DataFrame(index=np.arange(0, n), columns=["absGap", "dG1", "dG2", "dG3", "dG4", "dG5", "dG6", "dG7", "dG8","dG9", "dG10", "dG11", "dG12", "dG13", "dG14", "dG15", "dG16", "dG17", "dG18", "dG19", "dG20", "dG21", "d

Python
View
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" - "dG1", "dG2", "dG3",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.

global_dataframe = get_global_dataframe() global_dataframe = check_columns(global_dataframe) gKPI = KPI(global_dataframe) gKPI = gKPI.groupby('time').sum() NVEI = 128 NNewInd = 16 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)]) for i in gKPI.columns: RdataFrame[i][0] = gKPI[i][0] for sample in range(1000): SDFrame, Indexes = get_sample_dataframe(global_dataframe) sKPI = KPI(SDFrame) sKPI = sKPI.groupby('time').sum() absGap, detGap

Python
View
generate functionFri, 31 Mar 2023

read the dataframe "global_dataframe" from csv file "Sum Dat.csv" group by the columns "time" and "Volt" the mean value of the columns "NVEs" and "MWhT", concatenating the values of columns "time" and "Volt"

import pandas as pd import numpy as np def load_CSV(file): global_dataframe = pd.read_csv(file) global_dataframe["time"] = global_dataframe["Date"] + " " + global_dataframe["Time"] global_dataframe["time"] = pd.to_datetime(global_dataframe["time"]) global_dataframe["time"] = global_dataframe["time"].map(lambda x: x.strftime("%Y-%m-%d %H:%M")) global_dataframe = global_dataframe.groupby(["time", "Volt"]).agg( {"NVEs": np.mean, "MWhT": np.mean}) global_dataframe = global_dataframe.reset_index() return global_dataframe load_CSV("Sum Dat.csv")

Python
View
generate functionSat, 01 Apr 2023

dataframe "global_dataframe". Read information "Indexes" in a dataframe for the index [0] in the columns "Id1", "Id2", "Id3", etc. with 12 columns. Geta subDataFrame from "global_dataframe" containing only the information of indexes in "Indexes"

df = pd.DataFrame({'Id1': ['A', 'B', 'C', 'D', 'E'], 'Id2': ['F', 'G', 'H', 'I', 'J'], 'Id3': ['K', 'L', 'M', 'N', 'O']}) #print(df) def selectRows(inDataFrame, indexes): indexNames = indexes #print(indexNames) df2 = inDataFrame.loc[indexNames] return(df2) Indexes = ["0", "3"] df3 = selectRows(df, Indexes) print(df3)

Python
View
generate functionWed, 29 Mar 2023

Read the dataframe called "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". Call "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: - "absGap" - "dG1", "dG2", "dG3",etc. With "NVEI" columns. - "Id1","Id2","Id3", etc. With "NNewInd" columns. 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 func_read_from_csv(df_name, path): df_name = pd.read_csv(path) return df_name def func_kpi(df): df_ag = df.groupby(['Volts']).agg({'NEVs':'mean', 'MWhT':'mean'}) return df_ag def func_calc_new_ind(df): new_ind = np.random.choice(df.index, round(len(df.index)*0.1), replace=False) new_ind = new_ind.tolist() return new_ind def func_calc_NVEI(df): NVEI = df["Volts"].nunique() return NVEI global_dataframe = func_read_from_csv(global_dataframe,"Sum Data.csv") gKPI = func_kpi(global_dataframe) NNewInd = func_calc_new_ind(global_dataframe

Python
View
generate functionThu, 30 Mar 2023

given two dataframes calculate the absolute error of mean values of the columns "NEVs" and "MWhT" grouped by the columns "time" and "Volt" and the mean absolute error of both dataframes

def calculate_errors(df_model, df_measurements): df_model_agg = df_model.groupby(["time", "Volt"]).agg({"MWhT": "mean", "NEVs": "mean"}) df_measurements_agg = df_measurements.groupby(["time", "Volt"]).agg({"MWhT": "mean", "NEVs": "mean"}) df_abs_error = df_model_agg - df_measurements_agg df_abs_error["abs_error"] = df_abs_error.apply(lambda x: abs(x["MWhT"]) + abs(x["NEVs"]), axis=1) df_abs_error_mean = df_abs_error.mean() mean_abs_error = df_abs_error_mean["abs_error"] return mean_abs_error

Python
View
generate functionWed, 29 Mar 2023

Read the dataframe called "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: - "absGap" - "dG1", "dG2", "dG3",etc. With "NVEI" columns. - "Id1","Id2","Id3", etc. With "NNewInd" columns. 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 indexes choosen transposed in the dataframe "RdataFrame" in the columns "Id1","Id2","Id3",etc. - Execute "KPI" for "SDFrame" as "sKPI". - Calculate absolute error, "absGap", and detailed error, "detGap", between "sKPI" and "gKPI". - Store "absGap" and "detGap" in the dataframe "RdataFrame" in columns "aGap", "dG1", "dG2", "dG3",etc.

def readDataFrame(): global global_dataframe global_dataframe = pd.read_csv('Sum Data.csv', sep=';', decimal=',') def KPI(): return global_dataframe.groupby(["Volt"]).mean()[["NEVs", "MWhT"]] def executeKPI(df): return df.groupby(["Volt"]).mean()[["NEVs", "MWhT"]] def getNNewInd(): return round(global_dataframe.shape[0] * 0.1) def getNVEI(): return len(global_dataframe.Volt.unique()) def calcGap(m1, m2): return abs(m1 - m2) def calcDetGap(m1, m2): res = np.zeros(getNVEI()) for idx in range(getNVEI()): res[idx] = abs(m1.iloc[idx, 0] - m

Python
View
generate functionThu, 30 Mar 2023

Read the dataframe called "global_dataframe" from a csv file in current directory called "Sum Data.csv". Define "KPI": returning a dataframe "df" grouped by columns: "time" and "Volt" sumarizing the mean information of columns "NEVs" and "MWhT", including a key column composed by information of columns "time" and "volt". Calculate "NtVEl" as number of different elements of dataframe grouped by the columns "time" and "Volt" of "global_dataframe". Call "KPI" for "global_dataframe" as "gKPI". Calculate "NNewInd" as round the 10% of indexes of "global_dataframe". 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.

import pandas as pd import numpy as np import random global_dataframe = pd.read_csv('sum_data.csv') def KPI(df): KPI = df.groupby(["time","Volt"])["NEVs","MWhT"].mean() return KPI gKPI = KPI(global_dataframe) NVEI = len(gKPI.index.unique()) NNewInd = int(round(len(global_dataframe.index)*0.1)) RdataFrame = pd.DataFrame(index=range(1000), columns=["absGap","dG1","dG2","dG3","dG4","dG5","dG6","dG7","dG8","dG9","dG10","dG11","dG12","dG13","dG14","dG15","dG16","dG17","dG18","dG19","dG20","dG21","dG22","dG23","d

Python
View
generate functionWed, 29 Mar 2023

Read the dataframe called "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". Call "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 "Volt" of "global_dataframe". Define the dataframe "RdataFrame" with columns: - "absGap" - "dG1", "dG2", "dG3",etc. With "NVEI" columns. - "Id1","Id2","Id3", etc. With "NNewInd" columns. 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.

global_dataframe = pd.read_csv("Sum Data.csv") def KPI(df): KPI = df.groupby("Volt").mean()[["NEVs", "MWhT"]] return KPI gKPI = KPI(global_dataframe) NNewInd = int(round(len(global_dataframe.index)*0.1, 0)) NVEI = len(global_dataframe["Volt"].unique()) RdataFrame = pd.DataFrame(index=range(0,1000), columns=["absGap"] + ["dG" + str(x+1) for x in range(0, NVEI)] + ["Id" + str(x+1) for x in range(0, NNewInd)]) for Sample in range(0, 1000): Indexes = list(np.random.choice(global_dataframe.index, NNewInd, replace=False)) Indexes = [Indexes] SDFrame = global_dataframe.loc[Indexes,

Python
View
generate functionThu, 30 Mar 2023

Define "KPI" function for dataframe grouped by columns "time" and "Volts" for mean data of columns "NEVs" and "MWht". 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): return df.groupby(["time", "Volts"])[["NEVs", "MWht"]].mean() gKPI = KPI(global_dataframe) NVEI = len(gKPI.index) NNewInd = len(gKPI.index[0]) RdataFrame = pd.DataFrame( { "absGap": [0.0] * Samples, **{ "dG{}".format(i): [0.0] * NVEI for i in range(1, NVEI + 1) }, **{ "Id{}".format(i): [0.0] * NNewInd for i in range(1, NNewInd + 1) }, } ) for i in range(Samples): SDFrame = global_dataframe.sample(frac=0.1) sKPI = KPI(SDFrame) absGap = (sKPI - gKPI).

Python
View
generate functionWed, 29 Mar 2023

1. Read the dataframe "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.

def build_data_frame(global_dataframe): KPI = global_dataframe.groupby('Volt').mean().reset_index() gKPI = KPI.set_index("Volt").loc[global_dataframe.Volt] NNewInd = round(global_dataframe.shape[0] * 0.1) NVEl = global_dataframe["Volt"].unique().shape[0] RdataFrame = pd.DataFrame({"absGap": np.abs(gKPI.NEVs - global_dataframe.NEVs), "dG1": global_dataframe.NEVs - gKPI.NEVs.iloc[0], "dG2": global_dataframe.NEVs - gKPI.NEVs.iloc[1], "dG3": global_dataframe.NEVs - gKPI.NEVs.iloc[2], "dG4": global_dataframe.NEVs - gKPI.NEVs.iloc[

Python
View
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

Python
View
generate functionThu, 30 Mar 2023

Define the function "KPI" for dataframe grouped by columns "time" and "Volts" (concatenating them using the column name as delimiters) for mean data of columns "NEVs" and "MWht". 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.

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)]) def KPI(df): return df.groupby(by=["Time","Volt"]).mean()[["NEVs","MWht"]] for Sample in range(1000): SDFrame=global_dataframe.sample(frac=0.1) Indexes=SDFrame.index.values.reshape(NNewInd,1) sKPI=KPI(SDFrame) absGap=abs(gKPI.sum().sum()-sKPI.sum().sum()) detGap=[abs(gKPI.sum().sum()-sKPI[i].sum().sum()) for i in range(1,NVEI+1)] RdataFrame.loc[len(RdataFrame)]=[absGap]+detGap+[Index

Python
View
generate functionFri, 31 Mar 2023

read the dataframe "global_dataframe" from csv file "Sum Dat.csv" get the absolute error between the columns "EVa" and "EVb" grouped by column "TV" conserving the column "TV" transformed to string

def myfunction(df, col_name_a, col_name_b, group_by): new_df = pd.DataFrame(index=df[group_by].unique()) for i in range(0, new_df.shape[0]): subset = df[group_by] == i new_df.loc[i, 'abs error'] = abs(df.loc[subset, col_name_a] - df.loc[subset, col_name_b]).sum() new_df.loc[i, group_by] = str(i) return new_df

Python
View
generate functionWed, 29 Mar 2023

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 random import pandas as pd import numpy as np import matplotlib.pyplot as plt %matplotlib inline def samp(global_dataframe, NNewInd,NVEI): #1. Read the dataframe called "global_dataframe" from a csv file in current directory called "Sum Data.csv". global_dataframe = pd.read_csv('Sum Data.csv') #2. Define "KPI": Grouping the dataframe by column "Volt" and get mean information of columns "NEVs" and "MWhT". KPI = global_dataframe.groupby('Volt', as_index=False).agg({'NEVs': 'mean', 'MWhT': 'mean'}) #3. Execute "KPI" for "global_dataframe" as "gKPI". gKPI = global_dataframe.groupby('Volt', as_index=False).agg({'NEVs': 'mean', 'MWhT': 'mean'}) #4

Python
View
generate functionThu, 27 Apr 2023

1. Once open a file into the variable "filetxt" generate a function to search the identifier: "Resultados de la optimizacion". 2. Now read information spread by tabs in the next 48 lines only

filetxt = open('/home/david/Documents/python/logs_sas_v2/log_sas_opt_2/opt_2.txt','r') #search_text = 'Resultados de la optimizacion' def search_text(filetxt): for line in filetxt: if 'Resultados de la optimizacion' in line: return True return False filetxt.seek(0, 0) search_text(filetxt) def read_txt(filetxt, search_text): if search_text: print('Search_text: ', search_text) for i in range(0, 48): print(filetxt.readline(), end=' ') filetxt.seek(0, 0) read_txt(filetxt, search_text(filetxt))

Python
View
generate functionThu, 30 Mar 2023

Read the dataframe called "global_dataframe" from a csv file in current directory called "Sum Data.csv". Define "KPI": returning a dataframe "df" grouped by columns: "time" and "Volt" sumarizing the mean information of columns "NEVs" and "MWhT", concatenating the columns "time" and "volt" as in format "t\sV\s". Calculate "NtVEl" as number of different elements of dataframe grouped by the columns "time" and "Volt" of "global_dataframe". Call "KPI" for "global_dataframe" as "gKPI". Calculate "NNewInd" as round the 10% of indexes of "global_dataframe". 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 read_csv(): return pd.read_csv("Sum Data.csv") def KPI(df): return df.groupby(["time", "Volt"]).mean()[["NEVs", "MWhT"]].reset_index().rename(columns={"time": "t", "Volt": "V"}).assign(KPI=lambda x: x.apply(lambda x: f"{x.t}\sV{x.V}\s", axis=1)) def NVEI(df): return df.groupby(["time", "Volt"]).mean().shape[0] global_dataframe = read_csv() gKPI = KPI(global_dataframe) NVEI = NVEI(global_dataframe) NNewInd = int(round(global_dataframe.shape[0]*0.1)) RdataFrame = pd.DataFrame(columns=["absGap", *[f"dG{i}" for i in range(1, N

Python
View
generate functionSat, 01 Apr 2023

dataframe "global_dataframe". "Inds"=[0,2,15,166,1587] "Iterations" =[0,1,2,3,4] For each "Ite" in "Iterations" - Add a column called "Iteration" to a subdataframe "SDF" with the values of "global_dataframes" in the indexes "Inds" and "Ite" for all 5 indexes of "SDF". - print the value of "SDF" to a csv file called "SubDF" + "Ite" + ".csv".

def SDF(global_dataframe, Inds, Iterations): for Ite in Iterations: SDF = global_dataframe.iloc[Inds, Ite] outpath = r'Path'+'SubDF'+str(Ite)+'.csv' SDF.to_csv(outpath)

Python
View
generate functionFri, 31 Mar 2023

giving a list "VInd" with complete index data, complete the dataframe "global_dataframe" grouped by the column "Volt" with the mean value of columns "NEVs" and "MWhT" completing the index "Volt" with the information from "VInd" replacing the values NaN with the value of 0

def dataframe_fix(Vind, global_dataframe): global_dataframe_complete= global_dataframe.groupby("Volt").mean() global_dataframe_complete.loc[Vind] = 0 global_dataframe_complete.sort_index(inplace = True) global_dataframe_complete["NEVs"] = global_dataframe_complete["NEVs"].round(0) global_dataframe_complete["MWhT"] = global_dataframe_complete["MWhT"].round(2) return global_dataframe_complete

Python
View
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" - "dG1", "dG2", "dG3",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 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.

NVEI=128 NNewInd=16 RdataFrame=pd.DataFrame(index=range(1000),columns=["absGap"]+["dG"+str(i) for i in range(1,NVEI+1)]+["Id"+str(i) for i in range(1,NNewInd+1)]) RdataFrame.loc[0,["dG"+str(i) for i in range(1,NVEI+1)]]=gKPI["time"] for Sample in range(1000): SDFrame=global_dataframe.sample(frac=0.1,random_state=Sample) sKPI=KPI(SDFrame) absGap=abs(sKPI["time"].mean()-gKPI["time"].mean()) detGap=sKPI["time"].mean()-gKPI["time"].mean() RdataFrame.loc[Sample,"absGap"]=absGap RdataFrame.loc[Sample,["dG"+

Python
View
generate functionThu, 30 Mar 2023

Read the dataframe called "global_dataframe" from a csv file in current directory called "Sum Data.csv". Define "KPI": returning a dataframe "df" grouped by columns: "time" and "Volt" sumarizing the mean information of columns "NEVs" and "MWhT", concatenating the columns "time" and "volt" as in format "t%sV%s". Calculate "NtVEl" as number of different elements of dataframe grouped by the columns "time" and "Volt" of "global_dataframe". Call "KPI" for "global_dataframe" as "gKPI". Calculate "NNewInd" as round the 10% of indexes of "global_dataframe". 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): return df.groupby(['time', 'Volt'], as_index=False).agg({'NEVs': 'mean', 'MWhT': 'mean'}).rename(columns={'time': 'time', 'Volt': 'Volt', 'NEVs': 'NEVs', 'MWhT': 'MWhT'}) def RDFrame(df, NVEI, NNewInd): dG = ["dG" + str(i) for i in range(1, NVEI + 1)] Id = ["Id" + str(i) for i in range(1, NNewInd + 1)] RdataFrame = pd.DataFrame(columns=['absGap', *dG, *Id]) RdataFrame.loc[0] = np.nan RdataFrame.loc[1] = np.nan for i in range(NVEI): RdataFrame.loc[0, dG[i]] = [gKPI['time'][i], gK

Python
View
generate functionThu, 30 Mar 2023

Define "KPI" function 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): df_kpi = df[['time', 'Volt']] df_kpi['time'] = df_kpi['time'].abs() df_kpi = df_kpi.sort_values(by=['time']) df_kpi['time'] = df_kpi['time'] - df_kpi['time'].min() df_kpi = df_kpi.sort_values(by=['Volt']) df_kpi = df_kpi.reset_index(drop=True) df_kpi['diff'] = df_kpi['time'].diff() df_kpi['mean'] = df_kpi['diff'].mean() df_kpi['std'] = df_kpi['diff'].std() df_kpi['cov'] = df_kpi['diff'].std()/df_kpi['diff'].mean() df_kpi['Volt'] = df_kpi['Volt'] - df

Python
View
generate functionWed, 29 Mar 2023

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.

def read_data(): global global_dataframe global_dataframe = pd.read_csv("Sum Data.csv") global KPI KPI = global_dataframe.groupby("Volts").mean()[["NEVs","MWhT"]] global gKPI gKPI = KPI.loc[global_dataframe["Volts"]] global NNewInd NNewInd = pd.Series(round(0.1*len(global_dataframe))) global NVEI NVEI = len(global_dataframe["Volts"].unique()) global RdataFrame RdataFrame = pd.DataFrame(columns = ["absGap"] + ["dG"+str(i) for i in range(NVEI)] + ["Id"+str(i) for i in range(NNewInd)])

Python
View
generate functionWed, 29 Mar 2023

Read the dataframe called "global_dataframe" from a csv file in current directory called "Sum Data.csv". Define "KPI": Grouping the dataframe by column "Volts" and get mean information of columns "NEVs" and "MWhT". Call "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: - "absGap" - "dG1", "dG2", "dG3",etc. With "NVEI" columns. - "Id1","Id2","Id3", etc. With "NNewInd" columns. 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 "Volts" 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 main(): global_dataframe = pd.read_csv("Sum Data.csv") KPI = global_dataframe.groupby("Volts").mean()[["NEVs","MWhT"]] gKPI = KPI NNewInd = int(len(global_dataframe.index)*0.1) NVEl = len(global_dataframe["Volts"].unique()) RdataFrame = pd.DataFrame(columns=["absGap"]+["dG"+str(i) for i in range(1,NVEl+1)]+["Id"+str(i) for i in range(1,NNewInd+1)]) for Sample in range(1000): SDFrame = global_dataframe.sample(n=NNewInd) Indexes = SDFrame.index.tolist() sKPI = SDFrame.groupby("Volts").mean()[["NEVs","MWhT"]] absGap = abs(sKPI.sum().sum() -

Python
View
generate functionSat, 01 Apr 2023

dataframe "global_dataframe". "Iterations" =[0,1,2,3,4] For each "Ite" in "Iterations" - Add a column called "Iteration" to a subdataframe "SDF" with the values of "global_dataframes" and "Ite" for all 115 indexes of "SDF". - print the value of "SDF" to a csv file called "SubDF" + "Ite" + ".csv".

def generate_sub_dataframes(global_dataframe): Iterations = [0, 1, 2, 3, 4] for Ite in Iterations: SDF = global_dataframe SDF['Iteration'] = Ite print(SDF) SDF.to_csv("SubDF" + str(Ite) + ".csv", index=False, header=True)

Python
View
generate functionWed, 29 Mar 2023

Read the dataframe called "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". Call "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: - "absGap" - "dG1", "dG2", "dG3",etc. With "NVEI" columns. - "Id1","Id2","Id3", etc. With "NNewInd" columns. 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 indexes choosen transposed in the dataframe "RdataFrame" in the columns "Id1","Id2","Id3",etc. - Call "KPI" for "SDFrame" as "sKPI". - Calculate absolute error, "absGap", and detailed error, "detGap", between "sKPI" and "gKPI". - Store "absGap" and "detGap" in the dataframe "RdataFrame" in columns "aGap", "dG1", "dG2", "dG3",etc.

def main(): global_dataframe = pd.read_csv('Sum Data.csv') KPI = lambda dataframe : dataframe.groupby(['Volts']).mean()[['NEVs', 'MWhT']] gKPI = KPI(global_dataframe) NNewInd = round(len(global_dataframe.index)*0.1) NVEI = len(global_dataframe['Volts'].unique()) RdataFrame = pd.DataFrame(columns=["absGap"]+["dG"+str(x) for x in range (1,NVEI+1)]+["Id"+str(x) for x in range(1,NNewInd+1)]) samples = 1000 for sample in range (samples): SDFrame = global_dataframe.sample(frac=0.1) RdataFrame.loc[sample,'Id1':'Id'+str(NNewInd)]= SDFrame.index.values sKPI = KPI(SD

Python
View
generate functionSat, 01 Apr 2023

dataframe "global_dataframe". "Inds"=[0,2,15,166,1587] "Iterations" =[0,1,2,3,4] For each "Ite" in "Iterations" - Add a column called "Iteration" to a subdataframe "SDF" with the values of "global_dataframes" in the indexes "Inds" and "Ite" for all 115 indexes of "SDF". - print the value of "SDF" to a csv file called "SubDF" + "Ite" + ".csv".

Iterations = [0,1,2,3,4] Inds = [0,2,15,166,1587] for Ite in Iterations: SDF = global_dataframe.loc[Inds, [0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,52,53,54,55,56,57,58,59,60,61,62,63,64,65,66,67,68,69,70,71,72,73,74,75,76,77,78,79,80,81,82,83,84,85,86,87,88,89,90,91,92,93,94,95,96,

Python
View
generate functionThu, 27 Apr 2023

1. Once open a file into the variable "filetxt" generate a function to search the identifier: "Resultados de la optimizacion". 2. Into the function generate a table with the next information in the same line than the identifier if it is "solo carga sin EVs" Assign the value: "woEVs", elseif "minima carga requerida" Assign the value: "MinMCS", elseif "maxima carga requerida" Assign the value: "MaxMCS"

def searchidentifier(filetxt): for line in filetxt: if "Resultados de la optimizacion" in line: print(line) return line def search(filetxt): for line in filetxt: if "minima carga requerida" in line: print(line) return line elif "maxima carga requerida" in line: print(line) return line elif "solo carga sin EVs" in line: print(line) return line filetxt = open("00-pwr-baseline.txt", "r") searchidentifier(filetxt) search(filetxt)

Python
View
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". 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 read_data(): global global_dataframe global_dataframe = pandas.read_csv("Sum Data.csv") def KPI(df): sdf = df.groupby(["Volt"])["NEVs","MWhT"].mean() sdf.reset_index(level=0, inplace=True) return sdf def do_something(): RdataFrame = pandas.DataFrame(columns=("Id1","Id2","Id3","Id4", "Id5", "Id6", "Id7", "Id8", "Id9", "Id10", "aGap", "dG1", "dG2", "dG3","dG4", "dG5", "dG6", "dG7", "dG8", "dG9", "dG10")) gKPI = KPI(global_dataframe) gKPI.set_index("Volt", inplace=True) Samples = 1000 for i in range(Samples):

Python
View
generate functionThu, 27 Apr 2023

1. Open txt files from all the directories from you current directory, once in each directory open the directory "Sample" and the file "Sample.txt" 2. Once open each txt file, search the identifier: "Resultados de la optimizacion", once located read the information that continue in the same line. 3. Read the information from the next 48 lines 4. Finally apply the steps 2 and 3 2 more times

def open_txt_files(input_dir): for root, dirs, files in os.walk(input_dir): for file in files: if file.endswith(".txt"): f = open(os.path.join(root, file), "r") content = f.read() #Your code

Python
View
generate functionThu, 30 Mar 2023

Define the function "KPI" for dataframe grouped by columns "time" and "Volts" (concatenating them using the column name as delimiters) for mean data of columns "NEVs" and "MWht". Call the function "KPI" for the dataframe "global_dataframe" 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(dataframe): return dataframe.groupby(["Time","Volts"]).mean()[["NEVs","MWht"]] gKPI = KPI(global_dataframe) RdataFrame = pd.DataFrame(columns=["absGap"]+["dG"+str(i) for i in range(1,len(gKPI.index)+1)]+["Id"+str(i) for i in range(1,len(gKPI.index)+1)]) for s in range(0,1000): SDFrame = global_dataframe.sample(frac=0.1) Indexes = SDFrame.index sKPI = KPI(SDFrame) absGap = sum([abs(sKPI[col][i]-gKPI[col][i]) for i in range(0,len(gKPI.index))for col in gKPI.columns]) detGap = [abs(sKPI[col][i]-gKPI[col][i])

Python
View
generate functionSat, 01 Apr 2023

dataframe "global_dataframe". "Inds"=[0,2,15,166,1587,1658,1789] "Iterations" =[0,1,2,3,4] For each "Ite" in "Iterations" - Get subdataframe with the values of "global_dataframes" in the indexes "Inds" - Add a column called "Iteration" to the subdataframe "SDF" for all 7 indexes of "SDF". - print the value of "SDF" to a csv file called "SubDF" + "Ite" + ".csv".

for ite in iterations: inds = get_my_inds(ite) sdf = global_dataframe.iloc[inds] sdf['Iteration'] = ite sdf.to_csv('SubDF' + str(ite) + '.csv')

Python
View
generate functionSat, 01 Apr 2023

dataframe "global_dataframe". "Inds"=[0,2,15,166,1587,1658,1789] "Iterations" =[0,1,2,3,4] For each "Ite" in "Iterations" - Get subdataframe with the values of "global_dataframes" in the indexes "Inds" - Add a column called "Iteration" to the subdataframe "SDF" for all 7 indexes of "SDF". - Move the column "Iteration" to the first column place - print the value of "SDF" to a csv file called "SubDF" + "Ite" + ".csv".

# Create a list of indexes Inds = [0, 2, 15, 166, 1587, 1658, 1789] #Create a list of iterations Iterations = [0, 1, 2, 3, 4] #Create a function def create_file(global_dataframe, Inds, Iterations): for Ite in Iterations: #Get the subdataframe with the values of global_dataframe in the indexes Inds SDF = global_dataframe.iloc[Inds] #Add a column called "Iteration" to the subdataframe SDF for all 7 indexes of "SDF". SDF.loc[:,"Iteration"] = Ite #Move the column "Iteration" to the first column place SDF = SDF[["Iteration"] + [ col for col in SDF.columns if col != "Iteration"]] #print the value of "SDF" to a csv file called "SubDF" + "Ite" + ".csv". SDF.to_csv("Sub

Python
View
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)

Python
View
generate functionFri, 31 Mar 2023

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

def get_error(df1, df2, column_name): # df1 and df2 must be dataframes and column_name is the name of the column in both dataframes return abs(df1[column_name] - df2[column_name]).groupby(df1["TV"].apply(str)).mean()

Python
View
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

Python
View
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.

import pandas as pd def get_dataframe(): global_dataframe = pd.read_csv("Sum Data.csv") KPI = global_dataframe.groupby('Volt').mean().loc[:,['NEVs','MWhT']] gKPI = KPI.loc[global_dataframe["Volt"]] NNewInd = int(round(0.1*len(global_dataframe))) NVEI = len(global_dataframe["Volt"].unique()) 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)]) return global_dataframe, gKPI, NNewInd, NVEI, RdataFrame

Python
View
generate functionFri, 31 Mar 2023

giving a list "VInd" with complete index data and the dataframe "global_dataframe". Group "global_dataframe" by the column "Volt" with the mean value of columns "NEVs" and "MWhT" in the dataframe "SumDF". Complete the index "Volt" in "SumDF" with the information from "VInd" replacing the values NaN in the columns with the value of 0.

def summarize_with_NaN(global_dataframe, VoltInd): SumDF = global_dataframe.groupby("Volt").agg({"NEVs": "mean", "MWhT": "mean"}) VoltInd = VoltInd.fillna(0) for i, row in VoltInd.iterrows(): if row["Volt"] not in SumDF.index: SumDF.loc[row["Volt"]] = np.array([row["NEVs"], row["MWhT"]]) return SumDF summarize_with_NaN(global_dataframe, VoltInd)

Python
View
generate functionThu, 30 Mar 2023

Read the dataframe called "global_dataframe" from a csv file in current directory called "Sum Data.csv". Define "KPI": returning the dataframe grouped by columns: "time" and "Volt" with mean information of columns "NEVs" and "MWhT", including a key column composer by information of columns "time" and "volt". Calculate "NtVEl" as number of different elements of dataframe grouped by the columns "time" and "Volt" of "global_dataframe". Call "KPI" for "global_dataframe" as "gKPI". Calculate "NNewInd" as round the 10% of indexes of "global_dataframe". 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 run_sample(NVEI, NNewInd): gKPI = KPI() NVEI = gKPI.shape[0] RdataFrame = pd.DataFrame({'absGap':[0 for i in range(1000)], 'dG1':[0 for i in range(1000)],'dG2':[0 for i in range(1000)],'dG3':[0 for i in range(1000)],'dG4':[0 for i in range(1000)],'dG5':[0 for i in range(1000)],'dG6':[0 for i in range(1000)],'dG7':[0 for i in range(1000)],'dG8':[0 for i in range(1000)],'dG9':[0 for i in range(1000)],'dG10':[0 for i in range(1000)],'dG11':[0 for i in range(1000)],'dG12':[0 for i in range(1000)],'dG13':[0 for i in range(1000)],'dG14

Python
View
generate functionFri, 31 Mar 2023

giving a list "VInd"=[0.95,0.97,0.99,1.01,1.03,1.05] and the dataframe "global_dataframe". Group "global_dataframe" by the column "Volt" with the mean value of columns "NEVs" and "MWhT" in the dataframe "SumDF". Complete the index "Volt" in "SumDF" with the information from "VInd" filling the abscent information in the columns "NEVs" and "MWhT" with the value of 0.

import pandas as pd import numpy as np Volt = [0.95,0.97,0.99,1.01,1.03,1.05] NEVs = [0.95,0.97,0.99,1.01,1.03,1.05] MWhT = [0.95,0.97,0.99,1.01,1.03,1.05] df=pd.DataFrame({'Volt': Volt, 'NEVs': NEVs,'MWhT': MWhT}) Volt = [0.95,0.97,0.99,1.01,1.03,1.05] NEVs = [0.95,0.97,0.99,1.01,1.03,1.05] MWhT = [0.95,0.97,0.99,1.01,1.03,1.05] df=pd.DataFrame({'Volt': Volt, 'NEVs': NEVs,'MWhT': MWhT})

Python
View
generate functionThu, 30 Mar 2023

Define "KPI": returning a dataframe "df" grouped by columns: "time" and "Volt" sumarizing the mean information of columns "NEVs" and "MWhT", concatenating the columns "time" and "volt" as in format "t%sV%s". 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): kpi = (df.groupby(['time', 'Volt']) .agg({'NEVs': np.mean, 'MWhT': np.mean}) .reset_index() .rename(columns={'time': 't', 'Volt': 'v', 'NEVs': 'NEVs', 'MWhT': 'MWh'})) kpi['t%sv%s' % (kpi['t'][0], kpi['v'][0])] = kpi.NEVs kpi['t%sv%s' % (kpi['t'][0], kpi['v'][0])] = kpi.MWh kpi = kpi.drop(['t', 'v', 'NEVs', 'MWh'], axis=1) return kpi gKPI = KPI(global_dataframe) RdataFrame = pd.DataFrame(columns=['absGap'] + ['dG%s' % (i + 1) for

Python
View
generate functionSat, 01 Apr 2023

dataframe "global_dataframe". for the list "Iterations" =[0,1,2,3,4] add a column called "Iteration" to a subdataframe "SDF" with the values of "global_dataframes" and "Ite" for all 115 indexes of "SDF". For each "Ite" in "Iterations" print the value of "SDF" to a csv file called "SubDF" + "Ite" + ".csv".

import pandas as pd Iterations = [0,1,2,3,4] def make_subdataframes(global_dataframe): for Ite in Iterations: SDF = df[df['Iteration'] == Ite] SDF.to_csv('SubDF' + str(Ite) + '.csv')

Python
View
generate functionThu, 30 Mar 2023

Read the dataframe called "global_dataframe" from a csv file in current directory called "Sum Data.csv". Define "KPI": returning a dataframe "df" grouped by columns: "time" and "Volt" sumarizing the mean information of columns "NEVs" and "MWhT", concatenating the columns "time" and "volt" as in format "t%sV%s". Calculate "NtVEl" as number of different elements of dataframe grouped by the columns "time" and "Volt" of "global_dataframe". Call "KPI" for "global_dataframe" as "gKPI". Calculate "NNewInd" as round the 10% of indexes of "global_dataframe". 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.

import pandas as pd import numpy as np #Reading data global_dataframe = pd.read_csv('Sum Data.csv') #Defining KPI function def KPI(df): df = df.groupby(["Time", "Volt"]).agg({"NEVs": np.mean, "MWhT": np.mean}) df.reset_index(level=["Time", "Volt"], inplace=True) df["Time"] = "t" + df["Time"] df["Volt"] = "V" + df["Volt"] df["Time"] = df["Time"] + df["Volt"] df = df.drop(columns=["Volt"]) return df #Calculating NVEI NVEI = len(KPI(global_dataframe).index) #Calculating NNewInd NNewInd = int(0.1*len(global_dataframe)) #Defining RdataFrame RdataFrame = pd.DataFrame

Python
View
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"

Python
View
generate functionFri, 31 Mar 2023

read the dataframe "global_dataframe" from csv file "Sum Dat.csv" group by the columns "time" and "Volt" the mean value of the columns "NVEs" and "MWhT", concatenating the interger values of column "time" converted to string and the float values of column "Volt" converted to string

def global_dataframe(): global_dataframe = pd.read_csv('Sum Dat.csv') global_dataframe['Volt'] = global_dataframe['Volt'].astype(float) global_dataframe['NVEs'] = global_dataframe['NVEs'].astype(float) global_dataframe['MWhT'] = global_dataframe['MWhT'].astype(float) global_dataframe['time'] = global_dataframe['time'].astype(int) dat = global_dataframe.groupby(['time', 'Volt']).agg({'NVEs':np.mean, 'MWhT':np.mean}) dat.reset_index(inplace=True) dat['Volt'] = dat['Volt'].astype(str) dat['time'] = dat['time'].astype(str) dat['Volt'] = dat['time'].str.cat(dat['Volt'], sep =" ") dat['V

Python
View
generate functionThu, 30 Mar 2023

Read the dataframe called "global_dataframe" from a csv file in current directory called "Sum Data.csv". Define "KPI": Grouping the dataframe by columns: "time" and "Volt" and get mean information of columns "NEVs" and "MWhT". Calculate "NtVEl" as number of different elements of dataframe grouped by the columns "time" and "Volt" of "global_dataframe". Call "KPI" for "global_dataframe" as "gKPI". Calculate "NNewInd" as round the 10% of indexes of "global_dataframe". Define the dataframe "RdataFrame" with columns: - "absGap" - "dG1", "dG2", "dG3",etc. With "NVEI" columns. - "Id1","Id2","Id3", etc. With "NNewInd" columns. 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.

import pandas as pd import numpy as np def read_csv(): return pd.read_csv("Sum Data.csv") def KPI(df): return df.groupby(["time","Volt"]).agg(['mean'])[["NEVs","MWhT"]] def NVEI(df): return len(df.groupby(["time","Volt"])) def NNewInd(df): return round(len(df)*0.1) def SampleDF(df): return df.sample(NNewInd(df)) def Indexes(df): return df.index.values.reshape(1,NNewInd(df)) def sKPI(df): return KPI(df) def absGap(gKPI,sKPI): return abs(gKPI-sKPI) def detGap(gKPI,sKPI): return gKPI-sKPI def createR

Python
View
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.

def main(): global_dataframe = pd.read_csv("Sum Data.csv", index_col=0) gKPI = global_dataframe.groupby("Volt").mean()[["NEVs", "MWhT"]] NNewInd = math.floor(0.1 * len(global_dataframe.index)) NVEl = len(global_dataframe["Volt"].unique()) RdataFrame = pd.DataFrame(columns=["absGap"] + ["dG" + str(x) for x in range(1, NVEl + 1)] + ["Id" + str(x) for x in range(1, NNewInd + 1)]) pass

Python
View
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]

Python
View
generate functionThu, 30 Mar 2023

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 random_dataframe(df, I1, I2, NVEI, NNewInd): d1 = {'absGap': [0.0] * 1} for i in range(NVEI): d1['dG' + str(i + 1)] = [0.0] * 1 for i in range(NNewInd): d1['Id' + str(i + 1)] = [0.0] * 1 RdataFrame = pd.DataFrame(data=d1) for i in range(2): RdataFrame.at[i, ['dG1', 'dG2', 'dG3']] = (gKPI.loc[[0, 1], 'Volt':'time']) # RdataFrame.loc[0:1, ['dG1', 'dG2', 'dG3']] = (gKPI.loc[[0, 1], 'Volt':'time']) # WRONG! Samples = 1000 for Sample in range(Samples

Python
View

Questions about programming?Chat with your personal AI assistant