1

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?

user1977050
  • 496
  • 1
  • 6
  • 18
  • Does this answer your question? [How to join (merge) data frames (inner, outer, left, right)](https://stackoverflow.com/q/1299871/6381711) – nyedidikeke Aug 29 '21 at 09:32

1 Answers1

1

Do you mean by concat and sort_values:

print(pd.concat([df1, df2]).sort_values('time'))
U13-Forward
  • 69,221
  • 14
  • 89
  • 114