How to merge dataframe in dataframe

Question:

I am using Rest API. I need data in the form of a data frame. For this, I am using pandas. The query parameter of Rest API is connected to Database, so I am getting multiple outputs from Rest API. I want to merge these outputs in the same data frame.
Anyone can help me ?

cur.execute("SELECT * from curd")
rows = cur.fetchall()
l = []
for row in rows:
 #print("ID = ", row[1], "n")
  r = requests.get("http://localhost:8280/ID="+row[1], headers={uniquestr('Authorization'): 'Basic ',uniquestr('Authorization'): 'Basic'})
  #print("CONSUMER_ID = ", row[1], "n")
   s = r.json()
  df = pd.DataFrame(s['R']['L'])
  df1 = df.groupby(pd.to_datetime(df.DateTime).dt.date).agg({'ACT': 'sum'}).reset_index()

and Code output is

                  DateTime  ACT_IMP_TOT
   0            2022-05-01       19.252
   1            2022-05-02       19.911
   2            2022-05-03       23.671
                 DateTime  ACT_IMP_TOT
   0            2022-05-01       37.352
   1            2022-05-02       27.780
   2            2022-05-03       28.557
Asked By: riya

||

Answers:

Use pandas.concat():

pd.concat(df1, df2)

E.g. using pd.concat(df1, df2, df3):

enter image description here

So:

dfs = []

cur.execute("SELECT * from curd")
rows = cur.fetchall()
l = []
for row in rows:
 #print("ID = ", row[1], "n")
  r = requests.get("http://localhost:8280/ID="+row[1], headers={uniquestr('Authorization'): 'Basic ',uniquestr('Authorization'): 'Basic'})
  #print("CONSUMER_ID = ", row[1], "n")
   s = r.json()
  df = pd.DataFrame(s['R']['L'])
  df1 = df.groupby(pd.to_datetime(df.DateTime).dt.date).agg({'ACT': 'sum'}).reset_index()
  dfs.append(df1)
print(pd.concat(dfs))
Answered By: DialFrost
Categories: questions Tags: , , , ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.