Python | Pandas dataframe.get_dtype_counts()
Last Updated :
19 Nov, 2018
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.
Pandas dataframe.get_dtype_counts()
function returns the counts of dtypes in the given object. It returns a pandas series object containing the counts of all data types present in the pandas object. It works with pandas series as well as dataframe.
Syntax: DataFrame.get_dtype_counts()
Returns : value : Series : Counts of datatypes
For link to CSV file Used in Code, click here
Example #1: Use get_dtype_counts()
function to find the counts of datatype of a pandas dataframe object.
import pandas as pd
df = pd.read_csv( "nba.csv" )
df
|
Now apply the get_dtype_counts()
function. Find out the frequency of occurrence of each data type in the dataframe.
Output :
Notice, the output is a pandas series object containing the count of each data types in the dataframe.
Example #2: Use get_dtype_counts()
function over a selected no. of columns of the data frame only.
import pandas as pd
df = pd.read_csv( "nba.csv" )
df[[ "Salary" , "Name" , "Team" ]].get_dtype_counts()
|
Notice, the output is a pandas series object containing the count of each data types in the dataframe. We can verify all these results using this the dataframe.info()
function.
Output :
Like Article
Suggest improvement
Share your thoughts in the comments
Please Login to comment...