Python is a great language for doing data analysis, primarily because of the fantastic ecosystem of data-centric Python packages. Pandas is one of those packages and makes importing and analyzing data much easier.
.ndim are used to return size, shape and dimensions of data frames and series.
Return : Returns size of dataframe/series which is equivalent to total number of elements. That is rows x columns.
Return : Returns tuple of shape (Rows, columns) of dataframe/series
Return : Returns dimension of dataframe/series. 1 for one dimension (series), 2 for two dimension (dataframe)
To download the data set used in following example, click here.
In the following examples, the data frame used contains data of some NBA players. The image of data frame before any operations is attached below.
In this example, the output from size and shape is stored first. Since
.size returns total number of elements, it is compared by multiplying rows and columns returned by the shape method. After that dimension of Dataframe and series is also checked using
Size = 4122 Shape=(458, 9) Shape x Shape = 4122 ndim of dataframe = 2 ndim of series=1
As it can be seen, rows x columns from .shape is equal to the value returned by .size
Also, ndim for dataframe was 2 and series is 1 which is true for all kind of dataframes and series.
- Python | pandas.map()
- Python | Pandas Series.ge()
- Python | Pandas Series.ptp()
- Python | Pandas Series.ne()
- Python | Pandas Series.le()
- Python | Pandas TimedeltaIndex.take()
- Python | Pandas Panel.add()
- Python | Pandas Timestamp.day
- Python | Pandas Series.lt()
- Python | Pandas Series.pop()
- Python | Pandas Series.eq()
- Python | Pandas Panel.sub()
- Python | Pandas Panel.mul()
- Python | Pandas Period.second
- Python | Pandas Panel.div()
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.