The ndim
attribute returns the number of axes or array dimensions of the dataframe object.
DataFrame.ndim
The ndim
attribute takes no parameter value.
The ndim
attribute returns an integer value of 1
or 2
representing a Series or DataFrame, respectively.
# A code to illustrate the ndim attribute of a Dataframe# importing the pandas libraryimport pandas as pd# creating a series and a Dataframe objectsa = pd.Series({"row1": 1, "row2": 2, "row3": 3})b = pd.DataFrame({"col1":[1,2], "col2":[3,4]})# obtaining the array dimensionsprint(a.ndim)print(b.ndim)
pandas
library.a
and b
, respectively. a
and b
.