Suppose I have the following pandas series:
s = pd.Series([1,'1',1.0])
s.dtype
dtype('O')
When I check the types of each element I get the following:
type(s.iloc[0])
<class 'int'>
type(s.iloc[1])
<class 'str'>
type(s.iloc[2])
<class 'float'>
Is there a way to slice the pandas series based on the type of the elements?
Something like the following:
mask = s.types == 'str' # this doesn't exist
s[mask]
1 1
dtype: object
Ideally, I would want something that doesn't use loops (such as apply)