pandas 1.4.2

NotesParametersReturns
view(self, dtype: 'Dtype | None' = None) -> 'Series'

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.

Notes

Series are instantiated with dtype=float64 by 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 float64 and may fail if the original data type size in bytes is not the same.

Parameters

dtype : data type

Data type object or one of their string representations.

Returns

Series

A new Series object as a view of the same data in memory.

Create a new view of the Series.

See Also

numpy.ndarray.view

Equivalent numpy function to create a new view of the same data in memory.

Examples

This example is valid syntax, but we were not able to check execution
>>> s = pd.Series([-2, -1, 0, 1, 2], dtype='int8')
... s 0 -2 1 -1 2 0 3 1 4 2 dtype: int8

The 8 bit signed integer representation of :None:None:`-1` is :None:None:`0b11111111`, but the same bytes represent 255 if read as an 8 bit unsigned integer:

This example is valid syntax, but we were not able to check execution
>>> us = s.view('uint8')
... us 0 254 1 255 2 0 3 1 4 2 dtype: uint8

The views share the same underlying values:

This example is valid syntax, but we were not able to check execution
>>> us[0] = 128
... s 0 -128 1 -1 2 0 3 1 4 2 dtype: int8
See :

Local connectivity graph

Hover to see nodes names; edges to Self not shown, Caped at 50 nodes.

Using a canvas is more power efficient and can get hundred of nodes ; but does not allow hyperlinks; , arrows or text (beyond on hover)

SVG is more flexible but power hungry; and does not scale well to 50 + nodes.

All aboves nodes referred to, (or are referred from) current nodes; Edges from Self to other have been omitted (or all nodes would be connected to the central node "self" which is not useful). Nodes are colored by the library they belong to, and scaled with the number of references pointing them


File: /pandas/core/series.py#749
type: <class 'function'>
Commit: