Create a new view of the Series.
Deprecated since version 2.2.0:
Series.viewis deprecated and will be removed in a future version. Use
Series.astype()as an alternative to change the dtype.
This function will return a new Series with a view of the same underlying values in memory, optionally reinterpreted with a new data type. The new data type must preserve the same size in bytes as to not cause index misalignment.
- dtypedata type
Data type object or one of their string representations.
A new Series object as a view of the same data in memory.
Equivalent numpy function to create a new view of the same data in memory.
Series are instantiated with
dtype=float64by default. While
numpy.ndarray.view()will return a view with the same data type as the original array,
Series.view()(without specified dtype) will try using
float64and may fail if the original data type size in bytes is not the same.
astypeto change the dtype instead.