From 67a52ab00ad9bc9495e2bc2384a30a12b54db178 Mon Sep 17 00:00:00 2001 From: Florez Ospina Juan Felipe Date: Thu, 23 May 2024 22:20:19 +0200 Subject: [PATCH] Optimzed and included df to np structured array conversion. \n-Replaced loop plus append with list comprehension. \n-Replaced pd df column concatenation based on row-wise concatenation with df.aggr() method that uses column wise concatenation. --- src/g5505_file_reader.py | 11 +---------- 1 file changed, 1 insertion(+), 10 deletions(-) diff --git a/src/g5505_file_reader.py b/src/g5505_file_reader.py index 6f8ad28..d0f4b17 100644 --- a/src/g5505_file_reader.py +++ b/src/g5505_file_reader.py @@ -106,15 +106,6 @@ def dataframe_to_np_structured_array(df: pd.DataFrame): # Convert the DataFrame to a structured array structured_array = np.array(list(df.itertuples(index=False, name=None)), dtype=dtype) - #return structured_array - #table_header = df.columns - #table = df.to_numpy() - - #rows,cols = table.shape - #tmp = [tuple(table[i,:]) for i in range(rows)] - #dtype_tmp = [(table_header[i],'f4') for i in range(cols)] - #data = np.array(tmp, dtype=dtype_tmp) - return structured_array def read_txt_files_as_dict(filename : str ): @@ -210,7 +201,7 @@ def read_txt_files_as_dict(filename : str ): df_categorical_attrs['timestamps'] = df_categorical_attrs[timestamp_variables].astype(str).agg(' '.join, axis=1) df_categorical_attrs = df_categorical_attrs.drop(columns = timestamp_variables) - #print(df_categorical_attrs) + categorical_variables = [item for item in df_categorical_attrs.columns]