- Trending Categories
- Data Structure
- Operating System
- C Programming
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
What does the pandas.series.array attribute do?
The “.array” is one of the pandas series attributes. it will return a pandas ExtensionArray with the values stored in the series. The “.array” is used to get a zero-copy reference to the underlying data.
The resultant array is not like a NumPy array it is an ExtensionArray, and it has different array types based on the data present in the series (dtype).
import pandas as pd # create pandas series with numerical values s1 = pd.Series([1,2,3,4]) print(s1) print(s1.array)
The “s1” is the pandas series object which is created by using integer values with length 4. And we have applied the pandas array attribute to this series object s1.
0 1 1 2 2 3 3 4 dtype: int64 <PandasArray> [1, 2, 3, 4] Length: 4, dtype: int64
The resultant ExtensionArray is created for the series object “s1” that can be seen in the above output block which is PandasArray.
import pandas as pd # creating dates date = pd.date_range("2021-06-01", periods=5, freq="M") # creating pandas Series with date sequence s2 = pd.Series(date) print(s2) print(s2.array)
Let’s take a series with date-time sequence values, and get an ExtensionArray using the series attribute “.array”.
0 2021-06-30 1 2021-07-31 2 2021-08-31 3 2021-09-30 4 2021-10-31 dtype: datetime64[ns] <DatetimeArray> ['2021-06-30 00:00:00', '2021-07-31 00:00:00', '2021-08-31 00:00:00', '2021-09-30 00:00:00', '2021-10-31 00:00:00'] Length: 5, dtype: datetime64[ns]
In the following example, we can see a DatatimeArray created by using the “array” attribute. This DatatimeArray is a type of ExtensionArray which is for DateTime dtype data in pandas.
For any other 3rd-party dtype, the array type will be the ExtensionArray only.
- What does the pandas DataFrame.index attribute do?
- What does the pandas DataFrame.columns attribute do?
- What does count method do in the pandas series?
- What does the all() method do in pandas series?
- What does the add() method do in the pandas series?
- What does the align() method do in the pandas series?
- What does the any() method do in the pandas series?
- What does the apply() method do in the pandas series?
- What does agg() method do in pandas series?
- What does the pandas.series.index attribute do?
- What does the pandas.series.values attribute do?
- What does series mean in pandas?
- What does axes in the pandas series mean?
- What does the pandas series.filter() method do?
- What do axes attribute in the pandas DataFrame?