I am getting error while appending np.arrays into a DataFrame. Each np.array has varying length, so np.vstack will not work. What is the best way to deal with this?
Also, "y" needs to be sorted accordingly and the data I processed comes with different initial point --- I think it is easier to sort in DataFrame, but I haven't got to that point yet. Unless there's other suggestion? Thank you!
# For example:# In "n" loop, I will get y0, x0. Then in "n+1" loop, I will get y1, x1 and "n+1" loop to get y2, x2, etc.y0 = np.array([6,7,8,9])y1 = np.array([1,2,3,4,5])x0 = np.array([600, 700, 800, 900])x1 = np.array([0.1, 0.2, 0.3, 0.4, 0.5])# Ultimately, the DataFrame should return this:print(df) y x 0 1 0.11 2 0.22 3 0.33 4 0.44 5 0.55 6 6006 7 7007 8 8008 9 900
My current code:
df = pd.DataFrame({"data_y":[], "data_x":[]})for i in range(100): # Initiate lists data_y = [] data_x = [] # Data processed using list data_y, data_x = .... # Convert list to np.array data_y, data_x = .... # Compile data to DataFrame df["data_y"] = data_y.tolist() df["data_x"] = data_x.tolist()# ValueError: Length of values (111) does not match length of index (256)