Pandas Series.array
Pandas Series.array property
In this tutorial, we'll go through examples for the Pandas Series.array
property, which returns an array type ExtensionArray
object of the Pandas Series.
The Pandas Series.array
property is used to access the underlying array (data) of a Pandas Series. This property provides a way to work with the data in a more array-like fashion, allowing you to perform operations that are common in numerical computing and data manipulation.
Examples for Series.array property
1. Getting array type object of the given Series
In the following program, we take a Series object in series_data
, get the array data using Series.array
property, and print the contents of the array to output.
Python Program
import pandas as pd
# Create a Pandas Series
series_data = pd.Series([10, 20, 30, 40, 50])
# Get Series as array
array_data = series_data.array
# Display the array
print("Array")
print(array_data)
Output
Array
<NumpyExtensionArray>
[10, 20, 30, 40, 50]
Length: 5, dtype: int64
2. Getting array type object of the given Series with String values
In the following program, we take a Series with string values in series_data
, get the array data using Series.array
property, and print the contents of the array to output.
Python Program
import pandas as pd
# Create a Pandas Series
series_data = pd.Series(["apple", "banana", "cherry"])
# Get Series as array
array_data = series_data.array
# Display the array
print("Array")
print(array_data)
Output
Array
<NumpyExtensionArray>
['apple', 'banana', 'cherry']
Length: 3, dtype: object