
- Python Basic Tutorial
- Python - Home
- Python - Overview
- Python - Environment Setup
- Python - Basic Syntax
- Python - Comments
- Python - Variables
- Python - Data Types
- Python - Operators
- Python - Decision Making
- Python - Loops
- Python - Numbers
- Python - Strings
- Python - Lists
- Python - Tuples
- Python - Dictionary
- Python - Date & Time
- Python - Functions
- Python - Modules
- Python - Files I/O
- Python - Exceptions
Write a program in Python to count the total number of integer, float and object data types in a given series
Input − Assume, you have a series,
0 1 1 2 2 python 3 3 4 4 5 5 6 6.5
Output −
Total number of integer, float and string elements are, integer count: 5 float count: 1 string count: 1
Solution
To solve this, we will follow the steps given below −
Define a Series.
Create lambda filter method to extract the length of an integer value as follows,
len(pd.Series(filter(lambda x:type(x)==int,data)
Create lambda fliter method to extract length of float value as follows,
len(pd.Series(filter(lambda x:type(x)==float,data)
Create lambda fliter method to extract length of string value as follows,
len(pd.Series(filter(lambda x:type(x)==str,data)
Example
import pandas as pd ls = [1,2,"python",3,4,5,6.5] data = pd.Series(ls) print("integer count:",len(pd.Series(filter(lambda x:type(x)==int,data)))) print("float count:",len(pd.Series(filter(lambda x:type(x)==float,data)))) print("string count:",len(pd.Series(filter(lambda x:type(x)==str,data))))
Output
integer count: 5 float count: 1 string count: 1
- Related Articles
- Write a program in Python to count the total number of leap years in a given DataFrame
- Write a python program to count total bits in a number?
- Write a program in Python to filter only integer elements in a given series
- Write a program in Python to count the number of digits in a given number N
- Java program to Count the number of digits in a given integer
- Write a Python program to count the total number of ages between 20 to 30 in a DataFrame
- How to count total number of occurrences of an object in a Python list?
- Write a program in Python to print the first and last three days from a given time series data
- Write a program in Python to resample a given time series data and find the maximum month-end frequency
- Write a Python program to shuffle all the elements in a given series
- Write a program in Python to round all the elements in a given series
- Write a program in Python to calculate the default float quantile value for all the element in a Series
- Write a program in Python to filter valid dates in a given series
- Write a program in Python to filter armstrong numbers in a given series
- Write a program in Python to compute autocorrelation between series and number of lags

Advertisements