pandas.SparseDtype.update_dtype
-
SparseDtype.update_dtype(dtype)
[source] -
Convert the SparseDtype to a new dtype.
This takes care of converting the
fill_value
.Parameters: -
dtype : Union[str, numpy.dtype, SparseDtype]
-
The new dtype to use.
- For a SparseDtype, it is simply returned
- For a NumPy dtype (or str), the current fill value is converted to the new dtype, and a SparseDtype with
dtype
and the new fill value is returned.
Returns: - SparseDtype
-
A new SparseDtype with the corret
dtype
and fill value for thatdtype
.
Raises: - ValueError
-
When the current fill value cannot be converted to the new
dtype
(e.g. trying to convertnp.nan
to an integer dtype).
Examples
>>> SparseDtype(int, 0).update_dtype(float) Sparse[float64, 0.0]
>>> SparseDtype(int, 1).update_dtype(SparseDtype(float, np.nan)) Sparse[float64, nan]
-
© 2008–2012, AQR Capital Management, LLC, Lambda Foundry, Inc. and PyData Development Team
Licensed under the 3-clause BSD License.
https://pandas.pydata.org/pandas-docs/version/0.24.2/reference/api/pandas.SparseDtype.update_dtype.html