Given names of coordinates, reset them to become variables Parameters ---------- names : str, Iterable of Hashable or None, optional Name(s) of non-index coordinates in this dataset to reset into variables. By default, all non-index coordinates are re
(
self,
names: Dims = None,
drop: bool = False,
)
| 1866 | return obj |
| 1867 | |
| 1868 | def reset_coords( |
| 1869 | self, |
| 1870 | names: Dims = None, |
| 1871 | drop: bool = False, |
| 1872 | ) -> Self: |
| 1873 | """Given names of coordinates, reset them to become variables |
| 1874 | |
| 1875 | Parameters |
| 1876 | ---------- |
| 1877 | names : str, Iterable of Hashable or None, optional |
| 1878 | Name(s) of non-index coordinates in this dataset to reset into |
| 1879 | variables. By default, all non-index coordinates are reset. |
| 1880 | drop : bool, default: False |
| 1881 | If True, remove coordinates instead of converting them into |
| 1882 | variables. |
| 1883 | |
| 1884 | Examples |
| 1885 | -------- |
| 1886 | >>> dataset = xr.Dataset( |
| 1887 | ... { |
| 1888 | ... "temperature": ( |
| 1889 | ... ["time", "lat", "lon"], |
| 1890 | ... [[[25, 26], [27, 28]], [[29, 30], [31, 32]]], |
| 1891 | ... ), |
| 1892 | ... "precipitation": ( |
| 1893 | ... ["time", "lat", "lon"], |
| 1894 | ... [[[0.5, 0.8], [0.2, 0.4]], [[0.3, 0.6], [0.7, 0.9]]], |
| 1895 | ... ), |
| 1896 | ... }, |
| 1897 | ... coords={ |
| 1898 | ... "time": pd.date_range(start="2023-01-01", periods=2), |
| 1899 | ... "lat": [40, 41], |
| 1900 | ... "lon": [-80, -79], |
| 1901 | ... "altitude": 1000, |
| 1902 | ... }, |
| 1903 | ... ) |
| 1904 | |
| 1905 | # Dataset before resetting coordinates |
| 1906 | |
| 1907 | >>> dataset |
| 1908 | <xarray.Dataset> Size: 184B |
| 1909 | Dimensions: (time: 2, lat: 2, lon: 2) |
| 1910 | Coordinates: |
| 1911 | * time (time) datetime64[us] 16B 2023-01-01 2023-01-02 |
| 1912 | * lat (lat) int64 16B 40 41 |
| 1913 | * lon (lon) int64 16B -80 -79 |
| 1914 | altitude int64 8B 1000 |
| 1915 | Data variables: |
| 1916 | temperature (time, lat, lon) int64 64B 25 26 27 28 29 30 31 32 |
| 1917 | precipitation (time, lat, lon) float64 64B 0.5 0.8 0.2 0.4 0.3 0.6 0.7 0.9 |
| 1918 | |
| 1919 | # Reset the 'altitude' coordinate |
| 1920 | |
| 1921 | >>> dataset_reset = dataset.reset_coords("altitude") |
| 1922 | |
| 1923 | # Dataset after resetting coordinates |
| 1924 | |
| 1925 | >>> dataset_reset |