pandas系列isdigit()函数给出了NaN

时间:2016-04-04 19:27:16

标签: pandas nan

我在Pandas系列中使用了isdigit函数。即使系列中有整数,它也会给我NaN值。这可能是错的。

1 个答案:

答案 0 :(得分:2)

我认为您可以先按astype将列areacode转换为string,然后使用isdigit

employee = pd.DataFrame({'areacode':pd.Series([204,200,'AAA','BBB'])})
print employee
  areacode
0      204
1      200
2      AAA
3      BBB

employee['areacode'] = employee['areacode'].astype(str)
print employee.areacode.str.isdigit()
0     True
1     True
2    False
3    False
Name: areacode, dtype: bool

不转换获取NaN值:

employee = pd.DataFrame({'areacode':pd.Series([204,200,'AAA','BBB'])})

print employee.areacode.str.isdigit()
0      NaN
1      NaN
2    False
3    False
Name: areacode, dtype: object