Home > Back-end >  Is it possible to write a .csv file from a xarray.Dataset in python?
Is it possible to write a .csv file from a xarray.Dataset in python?

Time:04-03

I have been using the python package enter image description here

I would like to know if it is possible to create tabular data from this xarray.Dataset and export it as a single .csv or .txt file, following the data structure below:

 long   lat ur2m time variable            datetime
-47.8 -21.2    0    1     ur2m 2001-01-13 12:00:00
-47.4 -21.2    0    1     ur2m 2001-01-13 12:00:00
-47.0 -21.2    0    1     ur2m 2001-01-13 12:00:00
-46.6 -21.2    0    1     ur2m 2001-01-13 12:00:00
  ...   ...  ...  ...     <NA>        ...     <NA>
-37.4  -7.2    0  553     ur2m 2001-05-31 12:00:00
-37.0  -7.2    0  553     ur2m 2001-05-31 12:00:00
-36.6  -7.2    0  553     ur2m 2001-05-31 12:00:00
-36.2  -7.2    0  553     ur2m 2001-05-31 12:00:00

The original data are available here

CodePudding user response:

Try this: Convert netcdf to dataframe

df = ds.to_dataframe()

Save dataframe to csv

df = df.to_csv('df.csv')
  • Related