w3resource

Pandas Series property: values

Series as ndarray or ndarray-like in Pandas

The series-values property is used to get Series as ndarray or ndarray-like depending on the dtype.

Syntax:

Series.values
Pandas Series value property.

Returns: numpy.ndarray or ndarray-like

Example:

Python-Pandas Code:

import numpy as np
import pandas as pd 
pd.Series([3, 4, 5]).values
array([3, 4, 5], dtype=int64)
pd.Series(list('xxyz')).values

Output:

array(['x', 'x', 'y', 'z'], dtype=object)
Pandas Series value property.

Python-Pandas Code:

import numpy as np
import pandas as pd 
pd.Series([3, 4, 5]).values
pd.Series(list('xxyz')).astype('category').values

Output:

[x, x, y, z]
Categories (3, object): [x, y, z]
Pandas Series value property.

Example - Timezone aware datetime data is converted to UTC:

Python-Pandas Code:

import numpy as np
import pandas as pd 
pd.Series([3, 4, 5]).values
pd.Series(pd.date_range('20190402', periods=4,
                         tz='US/Eastern')).values

Output:

array(['2019-04-02T04:00:00.000000000', '2019-04-03T04:00:00.000000000',
       '2019-04-04T04:00:00.000000000', '2019-04-05T04:00:00.000000000'],
      dtype='datetime64[ns]')
Pandas Series value property.

Previous: An ExtensionArray in Pandas
Next: Memory usage of Pandas Series



Follow us on Facebook and Twitter for latest update.