1. 程式人生 > >Pandas 判斷字串型別

Pandas 判斷字串型別

In [1]: import pandas as pd
   ...: df=pd.Series(["1","a",1])
   ...: df
Out[1]: 
0    1
1    a
2    1
dtype: object

In [2]: df.str.isnumeric()
Out[2]: 
0     True
1    False
2      NaN
dtype: object

In [3]: df.str.isalnum()
Out[3]: 
0    True
1    True
2     NaN
dtype: object

In [4]: df.str.isalpha()
Out[4
]: 0 False 1 True 2 NaN dtype: object

NaN的意思是這不是一個字串,所以可以用這個語句來分別字串和非字串