I have 3 scripts at the end of each script i have a dataframe results and i want to run this 3 scrips from one script and to show results (3 dataframes) that i will regroupe in one dataframe. If you know how to run this 3 scripts at the same time and get results in one file (Dataframe)
CodePudding user response:
In scripts make sure you run them inside if __name__ == __main__:
block(so you don't run then while importing). Turn those scripts into functions (or classes, depending on the structure of your code) and then import them to the main python file. Then write their results to one file inside the main script.
CodePudding user response:
Something like this perhaps?
Main.py
import pandas as pd
from df_script_1 import script1
from df_script_2 import script2
if __name__ == __main__:
df1 = script1()
df2 = script2()
combined_df = pd.concat([df1, df2])
print(combined_df)
df_script_1.py
def script1():
# stuff that makes a DataFrame
return df
df_script_2.py
def script2():
# stuff that makes a DataFrame
return df