The simple answer to combining pipelines from different domains is to use the pandas concat
method. First run each pipeline separately and then combine the outputs. Something like this.
result_TH = run_pipeline(pipe_TH, start_period, end_period)
result_ID = run_pipeline(pipe_ID, start_period, end_period)
result_TH_ID = pd.concat([result_TH, result_ID])
However, nothing is that simple. There are two issues that will pop up. First, all the currency data (such as market cap, price, sales etc) are always in the local currency. So, once the two pipelines are merged it will be hard to do a lot of comparisons. This will even be the case in the original pipeline definitions. For instance the following market cap filter. This will have a different meaning for different domains since the market cap is denominated in the local currency.
marketcap_criteria = factset.Fundamentals.mkt_val.latest > 10000000000
The second issue is a pandas technical detail. One cannot concatenate dataframes with 'categorical' columns if the categories are not the same. What are 'categorical' columns? Anytime there is a string value (such as 'currency') that is a categorical. It's a column with a fixed set of potential values. So, this never comes up if all the pipeline outputs are numbers. Just do a simple concat
. However, if one has categories, then first you will need to set the categories of each dataframe to be all possible values between the dataframes. In the example below, we have a pipeline output column of 'currency'.
# First, make a list of all possible currencies across the dataframes. In this case just 2 currencies.
all_currencies = ['THB', 'IDR']
# Next, set the category values of each dataframe to all_currencies
result_TH.currency = pd.Categorical(result_TH.currency, categories=all_currencies )
result_ID.currency = pd.Categorical(result_ID.currency, categories=all_currencies )
# Now simply concat
result_TH_ID = pd.concat([result_TH, result_ID])
The biggest issue you will have is the first one. It will be difficult to compare values between domains.
Good luck.