I'd like to write an API that reads from a CSV on disk (with x, y coordinates) and outputs them in JSON format to be rendered by a web front end. The issue is that there are lots of data points (order of 30k) and so going from numpy arrays of x and y into JSON is really slow.
This is my current function to get the data in JSON format. Is there any way to speed this up? It seems very redundant to have such a large data structure for each 2d point.
def to_json(xdata, ydata):
data = []
for x, y in zip(xdata, ydata):
data.append({"x": x, "y": y})
return data
json.dumps([xdata.tolist(), ydata.tolist()]). Whatever plots likely wants two lists anyway.