How to Get the Number of Entries in a Pandas Dataframe Object in Python


In this article, we show how to get the number of entries in a pandas dataframe object in Python.

The number of entries in a pandas dateframe objects represents the number of data points entered into the dataframe objects. They represent the rows of data there are in the dataframe object.

Pandas supplies a built-in function, info(), which allows us to see certain information related to the dataframe object, including the number of entries in the dataframe. This is an easy way to check how many entries there are in the dataframe, although there are other such as using the shape() function. The info() function tells us teh number of entries, the number of columns, the names of the columns, the data types in the dataframe objects, and the memory used by the dataframe object.

To get the number of entries in a dataframe object, we use the name of the dataframe followed by a dot and the info() function.

This is shown in the following code below.

So the first thing we have to do is import seaborn as sns. We import as sns because it's an abbreviated shorthand way of referring to the seaborn module.

We then load a built-in dataframe from seaborn with the load_dataset() function. This is a dataframe that seaborn provides us with, without us needing to create our own. This could be used just for testing purposes.

One of the built-in datasets is the tips data set. We get this data set with the load_dataset() function.

We then show the full data set.

We use the info() function on the dataframe.

We can see that this returns 244 entries. So there are 244 data points in this dataframe. This spans from 0 to 243 entries (or rows).

The info() function also returns the number of columns, which in this case is 7.

It also returns the data type for each column and the memory that the dataframe object uses.

And this is one method of how to get the number of entries in a pandas dataframe object in Python.

Related Resources

How to Randomly Select From or Shuffle a List in Python

HTML Comment Box is loading comments...