'MSSQL statement in Python with multiple conditions, then adding together the dataframes

I am trying to create a sql statement in python to run, however I cannot figure out what I am doing wrong...

Desired output: Trying to add up both dataframes aligned with their date

My code:

v = ['fund_id1','fund_id2']

if len(v) > 1:
    v = "', '".join([x for x in v])

sql = ("select AS_OF_DATE, BEG_MKT_VALUE from STATESTREET..VW_PERFORMANCE_MONTHLY where FUND_ID in ('"+ v +"') and ISDEFAULT = 1")

data = pd.read_sql(sql, conn).set_index("AS_OF_DATE")

The data does pull, however not how i want it. It will pull fund_id1 in date order, but then append fund_id2 right after. Here is a snippet of data:

AS_OF_DATE  BEG_MKT_VALUE
2022-01-31  3168499925.823317
2022-02-28  3118078149.07385
2022-03-31  3083035936.290952
2015-05-31  
2015-06-30  0.06
2015-07-31  0.08
2015-08-31  0.07

As you can see, it begins to reset for fund_id2. How would i make them add together? Or at the very least, in different columns?



Sources

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

Source: Stack Overflow

Solution Source