I have an array of dataframe objects (columns of a larger dataframe) that I am passing into the Dataframe_Builder_Update
class. I am able to successfully update the date and associated calculation of the column objects with this code:
[setattr(obj, 'date', '12/29/2019') for obj in dataframe_builder_obj.column_builders]
but the build_dataframe()
class is not updating.
class Dataframe_Builder_Update():
def __init__(self, column_builders):
self._column_builders = column_builders
self.build_dataframe()
def build_dataframe(self):
self.result_df = pd.DataFrame()
for column_builder in self._column_builders:
if not column_builder.group:
self.result_df = pd.concat([self.result_df, column_builder.calculated_output], axis=0)
elif column_builder.group:
self.result_df = pd.concat([self.result_df, column_builder.calculated_output], axis=1)
@property
def column_builders(self):
return self._column_builders
@column_builders.setter
def column_builders(self, new_column_builders):
self._column_builders = new_column_builders
self.build_dataframe()
dataframe_builder_obj = Dataframe_Builder_Update(my_arr)
dataframe_builder_obj.result_df
old dataframe output (works correctly)
[setattr(obj, 'date', '12/29/2019') for obj in dataframe_builder_obj.column_builders]
dataframe_builder_obj.result_df
supposed to be the new dataframe output (does not work)
[setattr(obj, 'date', '12/29/2019') for obj in dataframe_builder_obj.column_builders]
dataframe_builder_obj.build_dataframe()
this works correctly but I just don't want to have to explicitly call the method
setattr
you are adding the same attribute and value to the instance at every iteration