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.
Attention geek! Strengthen your foundations with the Python Programming Foundation Course and learn the basics.
To begin with, your interview preparations Enhance your Data Structures concepts with the Python DS Course.
- Python | pandas.to_markdown() in Pandas
- Add a Pandas series to another Pandas series
- Replace the column contains the values 'yes' and 'no' with True and False In Python-Pandas
- Ceil and floor of the dataframe in Pandas Python – Round up and Truncate
- Login Application and Validating info using Kivy GUI and Pandas in Python
- Python | Pandas isnull() and notnull()
- Python | Data Comparison and Selection in Pandas
- Python | Difference between Pandas.copy() and copying through variables
- Python | Pandas Series.str.lower(), upper() and title()
- Python | Pandas Series.str.strip(), lstrip() and rstrip()
- Python | Working with date and time using Pandas
- Python | Pandas Series.str.ljust() and rjust()
- Python | Change column names and row indexes in Pandas DataFrame
- Python | Working with Pandas and XlsxWriter | Set - 1
- Python | Working with Pandas and XlsxWriter | Set – 2
- Python | Working with Pandas and XlsxWriter | Set – 3
- How to Install Python Pandas on Windows and Linux?
- How to Filter and save the data as new files in Excel with Python Pandas?
- Select first or last N rows in a Dataframe using head() and tail() method in Python-Pandas
- Get month and Year from Date in Pandas - Python
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.