In Pandas, how to filter a Series based on the type of the values?

前端 未结 3 529
逝去的感伤
逝去的感伤 2020-12-09 10:29

Given a Series like

import pandas as pd

s = pd.Series([\'foo\', \'bar\', 42])

I would like to obtain a \'sub-series\' p

3条回答
  •  北海茫月
    2020-12-09 11:19

    I'd use pd.to_numeric as pointed above.

    Alternatively, you can use str.isalpha

    In [109]: s[s.str.isalpha().notnull()]
    Out[109]:
    0    foo
    1    bar
    dtype: object
    

提交回复
热议问题