convert dataframe to netcdf multidimension using python

23 views Asked by At

i have a dataframe(df) of 100000 rows. i want to convert to a netcdf. i know the best way is xarray, but my df is bit complicated as follows

`*a              b      c     d        e            f*
[1,2,3...n]    4     5     8    [2,3...m]     [m*n matrix] 
[1,2,3...n]    5     5     8    [2,3...m]     [m*n matrix]  
[1,2,3...n]    4     5     10   [2,3...m]     [m*n matrix]   
.....100 k rows`

in the above a and e colomn are always the same for all rows.** b,c,d** colomns are repeatation of the values. now i want to create a netcdf where the attribute f is a 5-dimensional multidimension array of size mn*(uniques_values of b)*(uniques_values of c) (uniques_values of d)

since the number of rows are too many. it is better to avoid looping and use concurrancey

any good way is helpful, your text thanks in advance

i tried using the following but error

ds = df.set_index(['b', 'c', 'd']).to_xarray() ds.to_netcdf('~/test.nc')

0

There are 0 answers