user1977050
user1977050

Reputation: 526

pandas dataframe combining

I have a database which contains 2 tables. I'd like to get all the data from both tables into single dataframe. In both tables there is a time column on which I'd like to sort the data after the combining.

df1=pd.read_sql("Select * from table1")
df2=pd.read_sql("Select * from table2")

What is the best way to combine df1 and df2 to a single dataframe ordered by time column?

Upvotes: 1

Views: 50

Answers (1)

U13-Forward
U13-Forward

Reputation: 71580

Do you mean by concat and sort_values:

print(pd.concat([df1, df2]).sort_values('time'))

Upvotes: 1

Related Questions