Using SAS, I commonly use proc sql to create a dataset reading from a database. Later I can again use proc sql to query both from the database and from the first local dataset i created.
How does one do this in Python (using Pandas)?
Say in SAS, I run:
proc sql;
create table work.dataset1 as
select * from dbtable1;
run;
And then I can use this dataset to keep querying my database, as:
proc sql;
create table work.dataset2 as
select a.*, b.* from work.dataset1 a, dbtable2 b;
run;
I Python I have this code:
df1 = pd.read_sql_query("select * from dbtable1", conn)
And would like to be able to reference df1 in later queries, like:
df2 = pd.read_sql_query("select a.*, b.* from df1 a, dbtable2 b", conn)
But this does not seem to work.
Does anyone know how this can be done using Python/Pandas?
Many thanks in advance!