- Trending Categories
- Data Structure
- Operating System
- MS Excel
- C Programming
- Social Studies
- Fashion Studies
- Legal Studies
- 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 is NDIM in the pandas Series?
The ndim is an attribute in the pandas series which is used to get the integer representation of dimensions of a series object.
As we know, the pandas series is a 1-dimensional data structure so the output for this ndim property is always 1. It doesn’t take any input to get the dimensions. Regardless of the number of rows and columns, the ndim property always returns 1 for pandas Series.
In this following example, we have applied the ndim attribute to the pandas series object “s”.
# importing packages import pandas as pd import numpy as np # create pandas Series s = pd.Series(np.random.randint(1,100,10)) print("Series object:") print(s) # apply ndim property to get the dimensions print('Result:', s.ndim)
The output is given below −
Series object: 0 81 1 76 2 12 3 33 4 34 5 16 6 75 7 96 8 62 9 77 dtype: int32 Result: 1
As we can notice output in the above output block, the Series.ndim attribute has returned a value 1, which is indicating that the dimension of the given series object is 1.
Let's create another pandas series object with new elements and then apply the ndim attribute to get the dimensions of the series object.
# importing packages import pandas as pd dates = pd.date_range('2021-01-01', periods=10, freq='M') # create pandas Series s = pd.Series(dates) print("Series object:") print(s) # apply ndim property to get the dimensions print('Result:', s.ndim)
The output is as follows −
Series object: 0 2021-01-31 1 2021-02-28 2 2021-03-31 3 2021-04-30 4 2021-05-31 5 2021-06-30 6 2021-07-31 7 2021-08-31 8 2021-09-30 9 2021-10-31 dtype: datetime64[ns] Result: 1
We can notice that the ndim attribute returned output value 1 for both examples.
- Related Articles
- What is ndim in pandas DataFrame?
- What is the use of tail() methods in Pandas series?
- What is the use of head () methods in Pandas series?
- What is the use of abs() methods in pandas series?
- What is the use of rfloordiv() function in pandas series?
- What does axes in the pandas series mean?
- What does series mean in pandas?
- What does count method do in the pandas series?
- What does the all() method do in pandas series?
- What is a series data structure in Pandas library in Python?
- 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 happens if the specified index is not present in the series Python Pandas?