Created
April 8, 2021 12:33
-
-
Save tommylees112/69fdcbd1139e380429f6a501f47a35a0 to your computer and use it in GitHub Desktop.
example xarray to pandas conversion
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import xarray as xr | |
from pathlib import Path | |
if __name__ == "__main__": | |
data_dir = Path("/Users/tommylees/github/spatio_temporal/data") | |
# list(data_dir.glob("*.nc")) | |
ds = xr.open_dataset(data_dir / "camels_static.nc") | |
df = ds.to_dataframe() | |
print(df.head()) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
An example of how to use the xarray
.to_dataframe()
functionality. The reality is that most often you want netcdf format files to remain in xarray asxr.DataArray
orxr.Dataset
objects. But there are cases where it can make sense to convert topd.DataFrame
objects.