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