I have difficulty to get final concat dataframe by try except for pymssql

43 views Asked by At
for i in Com_Tables:
try:
    frames = [pd.read_sql(f"SELECT * FROM {i}", conn).assign(ComId_Code = i)]

except:
    pass

finally:
    dfxilnex = pd.concat(frames)

i am expecting output to concat all data from each item in list however the result is showing only data for last item in list

1

There are 1 answers

2
Serge de Gosson de Varennes On BEST ANSWER

You are not appending anything so there is nothing to concatnate. try this:

frames = []
for i in Com_Tables:
    try:
        frames.append(pd.read_sql(f"SELECT * FROM {i}", conn).assign(ComId_Code = i))

    except:
        pass

dfxilnex = pd.concat(frames)