Let’s say we have a dataset. We want to know the total number of non-null values in each column of the dataset. We can use the count() function in the pandas Python library to find out the same.
import pandas df = pandas.read_csv("iris.csv") print(df.head()) print("The total number of non-null values in each column: \n", df.count())
Here, we are first reading the iris dataset from a CSV file and creating the DataFrame df. After that, we are calling the DataFrame.count() function to find out the total number of non-null values in each column of the DataFrame.
The output of the above program will be:
sepal_length sepal_width petal_length petal_width species 0 5.1 3.5 1.4 0.2 setosa 1 4.9 3.0 1.4 0.2 setosa 2 4.7 3.2 1.3 0.2 setosa 3 4.6 3.1 1.5 0.2 setosa 4 5.0 3.6 1.4 0.2 setosa The total number of non-null values in each column: sepal_length 150 sepal_width 150 petal_length 150 petal_width 150 species 150 dtype: int64






0 Comments