ZulH
ZulH

Reputation: 13

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

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

Upvotes: 1

Views: 41

Answers (1)

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)

Upvotes: 0

Related Questions