I have a dataframe with columns that include latitude, longitude, time, and data values. I would like to reshape it and transform it into an xarray dataarray such that the dimensions are time x lat/long pair but am not sure of the most efficient way to do this.
To make it concrete, the dataframe is structured as follows:
Index Latitude Longitude Time Data
0 1 2 1 1
1 2 4 1 2
2 1 2 2 3
I want the data to be reshaped such that it ends up as a matrix:
Latitude 1/Longitude 2 Latitude 2/Longitude 4
Time 1 1 2
Time 2 3 Null
I’m currently doing this by taking a for loop over the unique lat/long combinations, saving each as an xarray, and then concatenating them over the lat/long dimension.
Are there any ways to more efficiency reshape the data?