I have a big array with 4 dimensions, as follow:
>>> raw_data
<xarray.DataArray 'TRAC04' (time: 3, Z: 34, YC: 588, XC: 2160)>
[129548160 values with dtype=float32]
Coordinates: (12/15)
iter (time) int64 ...
* time (time) datetime64[ns] 2017-01-30T12:40:00 ... 2017-04-01T09:20:00
* XC (XC) float32 0.08333 0.25 0.4167 0.5833 ... 359.6 359.8 359.9
* YC (YC) float32 -77.98 -77.95 -77.91 -77.88 ... -30.02 -29.87 -29.72
* Z (Z) float32 -2.1 -6.7 -12.15 -18.55 ... -614.0 -700.0 -800.0
rA (YC, XC) float32 ...
... ...
maskC (Z, YC, XC) bool ...
maskCtrlC (Z, YC, XC) bool ...
rhoRef (Z) float32 ...
rLowC (YC, XC) float32 ...
maskInC (YC, XC) bool ...
rSurfC (YC, XC) float32 ...
Attributes:
standard_name: TRAC04
long_name: Variable concentration
units: mol N/m^3
I want to transform it into a Dataframe with 5 columns, as 'XC', 'YC', 'Z', 'time', 'TRAC04'.
I tried to follow this question like this:
import itertools
data = list(itertools.chain(*raw_data))
df = pd.DataFrame.from_records(data)
it runs it, however, I do not see creating anything in the environment. Furthermore, if I try to look at df
with pd.head(df)
, it does run forever, without giving back outputs.
I tried, in any case, to save df
, following this question, but it runs without ending also in this case:
np.savetxt(r'c:\data\DF_TRAC04.txt', df.values, fmt='%d')
df.to_csv(r'c:\data\DF_TRAC04.csv', header=None, index=None, sep=' ', mode='a')