Skip to content
Advertisement

Python – loop through same query with different variables, merge data frames

I have a query in SAS where I use a Macro variable to repeat a query to Teradata with a different variable. We have 5 databases, one for each state, where I run the same query, but use the variable to update the state, then mend all data sets. I’m looking for help in how I can do this in python.

loop through {state1, state2, state3, state4, state5} and save each query as {stateX}_df then merge all

Advertisement

Answer

Here is an improved version with volatile table use: Python SQL loop variables through multiple queries

User contributions licensed under: CC BY-SA
4 People found this is helpful
Advertisement