TheDeveloperBlog.com

Home | Contact Us

C-Sharp | Java | Python | Swift | GO | WPF | Ruby | Scala | F# | JavaScript | SQL | PHP | Angular | HTML

Pandas count()

Pandas count() with What is Python Pandas, Reading Multiple Files, Null values, Multiple index, Application, Application Basics, Resampling, Plotting the data, Moving windows functions, Series, Read the file, Data operations, Filter Data etc.

<< Back to PANDAS

Pandas DataFrame.count()

The Pandas count() is defined as a method that is used to count the number of non-NA cells for each column or row. It is also suitable to work with the non-floating data.

Syntax:

DataFrame.count(axis=0, level=None, numeric_only=False)

Parameters:

  • axis: {0 or 'index', 1 or 'columns'}, default value 0
    0 or 'index' is used for row-wise, whereas 1 or 'columns' is used for column-wise.
  • level: int or str
    It is an optional parameter. If an axis is hierarchical, it counts along with the particular level and collapsing into the DataFrame.
  • numeric_only: bool, default value False
    It only includes int, float, or Boolean data.

Returns:

It returns the count of Series or DataFrame if the level is specified.

Example 1: The below example demonstrates the working of the count().

import pandas as pd
import numpy as np
info = pd.DataFrame({"Person":["Parker", "Smith", "William", "John"],
"Age": [27., 29, np.nan, 32]
info.count()

Output

Person    5
Age       3
dtype: int64

Example 2: If we want to count for each of the row, we can use the axis parameter. The below code demonstrates the working of the axis parameter.

import pandas as pd
import numpy as np
info = pd.DataFrame({"Person":["Parker", "Smith", "William", "John"],
"Age": [27., 29, np.nan, 32]
info.count(axis='columns')

Output

0       2
1       2
2       1
3       2
dtype: int64

Next TopicDataFrame.cut()




Related Links:


Related Links

Adjectives Ado Ai Android Angular Antonyms Apache Articles Asp Autocad Automata Aws Azure Basic Binary Bitcoin Blockchain C Cassandra Change Coa Computer Control Cpp Create Creating C-Sharp Cyber Daa Data Dbms Deletion Devops Difference Discrete Es6 Ethical Examples Features Firebase Flutter Fs Git Go Hbase History Hive Hiveql How Html Idioms Insertion Installing Ios Java Joomla Js Kafka Kali Laravel Logical Machine Matlab Matrix Mongodb Mysql One Opencv Oracle Ordering Os Pandas Php Pig Pl Postgresql Powershell Prepositions Program Python React Ruby Scala Selecting Selenium Sentence Seo Sharepoint Software Spellings Spotting Spring Sql Sqlite Sqoop Svn Swift Synonyms Talend Testng Types Uml Unity Vbnet Verbal Webdriver What Wpf