Skip to content

Commit 1ab2279

Browse files
authored
Add how do I ... section (#3357)
* Add how do I ... section * Bbugfix. * Update doc/howdoi.rst Co-Authored-By: Maximilian Roos <[email protected]> * Update doc/howdoi.rst Co-Authored-By: Maximilian Roos <[email protected]> * small updates. * Add more.
1 parent bd1069b commit 1ab2279

File tree

5 files changed

+74
-1
lines changed

5 files changed

+74
-1
lines changed

doc/_static/style.css

+9
Original file line numberDiff line numberDiff line change
@@ -16,3 +16,12 @@
1616
.wy-nav-top {
1717
background-color: #555;
1818
}
19+
20+
table.colwidths-given {
21+
table-layout: fixed;
22+
width: 100%;
23+
}
24+
table.docutils td {
25+
white-space: unset;
26+
word-wrap: break-word;
27+
}

doc/howdoi.rst

+59
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
.. currentmodule:: xarray
2+
3+
.. _howdoi:
4+
5+
How do I ...
6+
============
7+
8+
.. list-table::
9+
:header-rows: 1
10+
:widths: 40 60
11+
12+
* - How do I...
13+
- Solution
14+
* - add variables from other datasets to my dataset
15+
- :py:meth:`Dataset.merge`
16+
* - add a new dimension and/or coordinate
17+
- :py:meth:`DataArray.expand_dims`, :py:meth:`Dataset.expand_dims`
18+
* - add a new coordinate variable
19+
- :py:meth:`DataArray.assign_coords`
20+
* - change a data variable to a coordinate variable
21+
- :py:meth:`Dataset.set_coords`
22+
* - change the order of dimensions
23+
- :py:meth:`DataArray.transpose`, :py:meth:`Dataset.transpose`
24+
* - remove a variable from my object
25+
- :py:meth:`Dataset.drop`, :py:meth:`DataArray.drop`
26+
* - remove dimensions of length 1 or 0
27+
- :py:meth:`DataArray.squeeze`, :py:meth:`Dataset.squeeze`
28+
* - remove all variables with a particular dimension
29+
- :py:meth:`Dataset.drop_dims`
30+
* - convert non-dimension coordinates to data variables or remove them
31+
- :py:meth:`DataArray.reset_coords`, :py:meth:`Dataset.reset_coords`
32+
* - rename a variable, dimension or coordinate
33+
- :py:meth:`Dataset.rename`, :py:meth:`DataArray.rename`, :py:meth:`Dataset.rename_vars`, :py:meth:`Dataset.rename_dims`,
34+
* - convert a DataArray to Dataset or vice versa
35+
- :py:meth:`DataArray.to_dataset`, :py:meth:`Dataset.to_array`
36+
* - extract the underlying array (e.g. numpy or Dask arrays)
37+
- :py:attr:`DataArray.data`
38+
* - convert to and extract the underlying numpy array
39+
- :py:attr:`DataArray.values`
40+
* - find out if my xarray object is wrapping a Dask Array
41+
- :py:func:`dask.is_dask_collection`
42+
* - know how much memory my object requires
43+
- :py:attr:`DataArray.nbytes`, :py:attr:`Dataset.nbytes`
44+
* - convert a possibly irregularly sampled timeseries to a regularly sampled timeseries
45+
- :py:meth:`DataArray.resample`, :py:meth:`Dataset.resample` (see :ref:`resampling` for more)
46+
* - apply a function on all data variables in a Dataset
47+
- :py:meth:`Dataset.apply`
48+
* - write xarray objects with complex values to a netCDF file
49+
- :py:func:`Dataset.to_netcdf`, :py:func:`DataArray.to_netcdf` specifying ``engine="h5netcdf", invalid_netcdf=True``
50+
* - make xarray objects look like other xarray objects
51+
- :py:func:`~xarray.ones_like`, :py:func:`~xarray.zeros_like`, :py:func:`~xarray.full_like`, :py:meth:`Dataset.reindex_like`, :py:meth:`Dataset.interpolate_like`, :py:meth:`Dataset.broadcast_like`, :py:meth:`DataArray.reindex_like`, :py:meth:`DataArray.interpolate_like`, :py:meth:`DataArray.broadcast_like`
52+
* - replace NaNs with other values
53+
- :py:meth:`Dataset.fillna`, :py:meth:`Dataset.ffill`, :py:meth:`Dataset.bfill`, :py:meth:`Dataset.interpolate_na`, :py:meth:`DataArray.fillna`, :py:meth:`DataArray.ffill`, :py:meth:`DataArray.bfill`, :py:meth:`DataArray.interpolate_na`
54+
* - extract the year, month, day or similar from a DataArray of time values
55+
- ``obj.dt.month`` for example where ``obj`` is a :py:class:`~xarray.DataArray` containing ``datetime64`` or ``cftime`` values. See :ref:`dt_accessor` for more.
56+
* - round off time values to a specified frequency
57+
- ``obj.dt.ceil``, ``obj.dt.floor``, ``obj.dt.round``. See :ref:`dt_accessor` for more.
58+
* - make a mask that is ``True`` where an object contains any of the values in a array
59+
- :py:meth:`Dataset.isin`, :py:meth:`DataArray.isin`

doc/index.rst

+2
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@ Documentation
8484
**Help & reference**
8585

8686
* :doc:`whats-new`
87+
* :doc:`howdoi`
8788
* :doc:`api`
8889
* :doc:`internals`
8990
* :doc:`roadmap`
@@ -96,6 +97,7 @@ Documentation
9697
:caption: Help & reference
9798

9899
whats-new
100+
howdoi
99101
api
100102
internals
101103
roadmap

doc/time-series.rst

+2
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,8 @@ You can also select a particular time by indexing with a
101101
102102
For more details, read the pandas documentation.
103103

104+
.. _dt_accessor:
105+
104106
Datetime components
105107
-------------------
106108

doc/whats-new.rst

+2-1
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,8 @@ Documentation
3333

3434
- Created a glossary of important xarray terms (:issue:`2410`, :pull:`3352`).
3535
By `Gregory Gundersen <https://github.com/gwgundersen/>`_.
36-
36+
- Created a "How do I..." section (:ref:`howdoi`) for solutions to common questions. (:pull:`3357`).
37+
By `Deepak Cherian <https://github.com/dcherian/>`_.
3738
- Add examples for :py:meth:`Dataset.swap_dims` and :py:meth:`DataArray.swap_dims`.
3839
By `Justus Magin <https://github.com/keewis>`_.
3940
- Add examples for :py:meth:`align`, :py:meth:`merge`, :py:meth:`combine_by_coords`,

0 commit comments

Comments
 (0)