Pandas Series.ndim
Pandas Series.ndim property
In this tutorial, we'll go through examples for the Pandas Series.ndim
property, which returns the dimensions of the Series data.
By definition Series is one dimensional, and therefore ndim
property of any Pandas Series object returns 1
.
Examples for Series.ndim property
1. Getting number of dimension in given Pandas Series
In the following program, we take a Series object in series_data
, and get the number of dimensions in this Series object using Series.ndim
property.
Python Program
import pandas as pd
# Create a Pandas Series
series_data = pd.Series([10, 20, 30, 40, 50])
# Get number of dimensions in the Series data
n_dimensions = series_data.ndim
# Display the result
print(f"Number of dimensions\n{n_dimensions}")
Output
Number of dimensions
1
2. Getting the number of dimensions in given Pandas Series with String values
In the following program, we take a Series object in series_data
with string values, and get the number of dimensions in this Series object using Series.ndim
property.
Python Program
import pandas as pd
# Create a Pandas Series
series_data = pd.Series(["apple", "banana", "cherry"])
# Get number of dimensions in the Series data
n_dimensions = series_data.ndim
# Display the result
print(f"Number of dimensions\n{n_dimensions}")
Output
Number of dimensions
1