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
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)
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]
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]')
Previous: An ExtensionArray in Pandas
Next: Memory usage of Pandas Series
It will be nice if you may share this link in any developer community or anywhere else, from where other developers may find this content. Thanks.
https://www.w3resource.com/pandas/series/series-values.php
- Weekly Trends and Language Statistics
- Weekly Trends and Language Statistics