How to write the OOP file that returns output without intermediate results?

Viewed 18

I'm writing a OOP class that takes 2 data frames and concatenate them. The concat.py file looks like this:

import pandas as pd

class DataIngest:
    def __init__(self, some args):
        # Arguments defined here
    def get_df_1(self, df_1_path, some args):
        df_1 = pd.read_excel(df_1_path)
        # Also do some steps with df_1 but omitted for simplicity
        return df_1
    def get_df_2(self, df_2_path, some args):
        df_2 = pd.read_excel(df_2_path)
        # Also do some steps with df_2 but omitted for simplicity
        return df_2
    def concat_df(df_1, df_2):
        df_all = pd.concat([df_1, df_2], ignore_index = True, sort = False)

Then I can call the class and methods in a notebook to get the data frame I need:

DataIngest = DataIngest(args)
df_1 = DataIngest.get_df_1(df_1_path)
df_2 = DataIngest.get_df_2(df_2_path)
df_all = DataIngest.concat_df(df_1, df_2)

My question is: How can I write the .py file so that it returns df_all with a single run without having to return df_1 and df_2, like getting df_all by just %run ./concat.py? Or similarly, in case I call the class, I can get df_all just by running DataIngest(args)?

0 Answers
Related