können Sie list comprehension
verwenden für die Überprüfung nicht ganzzahlige Werte, wenn type
Werte string
und integer
:
import pandas as pd
a=['a',3,4,5,6,2,8,5,9]
s = pd.Series(a)
print s
0 a
1 3
2 4
3 5
4 6
5 2
6 8
7 5
8 9
dtype: object
print [type(x) for x in s]
[<type 'str'>, <type 'int'>, <type 'int'>, <type 'int'>, <type 'int'>, <type 'int'>, <type 'int'>, <type 'int'>, <type 'int'>]
print [type(x) == int for x in s]
[False, True, True, True, True, True, True, True, True]
Oder von to_numeric
mit notnull
:
print pd.to_numeric(s, errors='coerce').notnull()
0 False
1 True
2 True
3 True
4 True
5 True
6 True
7 True
8 True
dtype: bool
Wenn Werte int
und float
, Series
konvertieren Sie alle Werte in float
:
import pandas as pd
a=[1.2,3,4,5,6,2,8,5,9]
s = pd.Series(a)
print s
0 1.2
1 3.0
2 4.0
3 5.0
4 6.0
5 2.0
6 8.0
7 5.0
8 9.0
dtype: float64
print [type(x) for x in s]
[<type 'numpy.float64'>, <type 'numpy.float64'>, <type 'numpy.float64'>, <type 'numpy.float64'>, <type 'numpy.float64'>, <type 'numpy.float64'>, <type 'numpy.float64'>, <type 'numpy.float64'>, <type 'numpy.float64'>]
Sie tun könnte 'a.apply (lambda x: isinstance (x, int))' oder was auch immer das ist, aber es wird für große Daten – EdChum