Let's say you have 3 numpy array: lat
, lon
, val
:
import numpy as np
lat=np.array([[10, 20, 30],
[20, 11, 33],
[21, 20, 10]])
lon=np.array([[100, 102, 103],
[105, 101, 102],
[100, 102, 103]])
val=np.array([[17, 2, 11],
[86, 84, 1],
[9, 5, 10]])
And say that you want to create a pandas
dataframe where df.columns = ['lat', 'lon', 'val']
, but since each value in lat
is associated with both quantity long
and s val
, you want them to appear on the same line.
In addition, you want the row order of each column to correspond to the positions in each array, therefore, to get the following data frame:
lat lon val
0 10 100 17
1 20 102 2
2 30 103 11
3 20 105 86
... ... ... ...
So basically the first line in the dataframe stores the "first" quantities of each array, etc. How to do it?
I could not find a pythonic way to do this, so any help would be greatly appreciated.