'Dataclasses for dataframes in the class

I have a Result class in which I calculate many dataframes (around 30) and assign them to attributes of the class.

class Result:
    def __init__(self, df1)
      self.df1=df1

I want to write the dataframes to excel at specified positions. For this I have a function

append_df_to_excel(df, sheet_name='Sheet1', startrow=0, startcol=0)

which takes as parameters a dataframe, sheet_name and startrow and startcolumn.

What I am doing for now is I have a dictionary in the function main and I iterate thourgh it to write dataframes at specified places in the excel:

if __name__ == "__main__":
      result=Result(df)
      dic_to_excel = {5:result.df1}
      for start_col, df in dic_to_excel.items():
          append_df_to_excel(df, sheet_name="CORE", startrow=2, startcol=start_col)

I am wondering if it is a right place to use a dataclass instead of this dictionary dic_to_excel in which i give poition of a dataframe in excel. In the dataclass I thought I could have a dataframe, sheet_name , startrow and startcol as attributes. Can I use dataclasses for this?



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source