I am using python pandas to execute query on MySql. In UI side using Flot API to represent the MySql data. Below is the existing implementation,
query2 = f"""select time, value from NWSTAT
where time > \'{from_date}\'
and time < \'{to_date}\'"""
result2 = pd.read_sql(query2, engine)
return result2.to_json(orient='records')
Getting result in below format
[{"time": 1581931200000, "value": 0.0}, {"time": 1581931200000, "value": 0.0},
{"time": 1581931200000, "value": 0.0}, {"time": 1581931200000, "value": 0.0}]
From this response I am creating belwo structure for Flot API in UI Javascript side,
[[1581931200000,0],[1581931200000,0],[1581931200000,0],[1581931200000,0]]
Is there any way to do this in python side itself with out any iterations? Directly from query result.
Using Flask server. UI side: JQuery, Handlebar JS
EDIT: In accepted answer second approach takes lesser time.. Below is the time taken for both approach for 240k records
First one: --- 1.6689300537109375e-06 seconds ---
Second one: --- 0.5330650806427002 seconds ---