Home > Enterprise >  How to merge dataframe in dataframe
How to merge dataframe in dataframe

Time:08-19

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

CodePudding user response:

Use 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))
  • Related