2016-03-29 7 views
0

pandasシリーズオブジェクトのfloat、stringのような非整数値の検索方法は?パンダシリーズオブジェクトの非整数値の検索

は、このような一連のオブジェクトを持って、

a=(1.2,3,4,5,6,2,8,5,9) 

は私がto_numericを試してみましたが、これはfloat値を識別するために支援されていません。 integerの値を確認する方法はありますか?

値の typestringintegerある場合は、非整数値をチェックするため list comprehensionを使用することができます
+1

あなたは 'a.apply(ラムダX:でisinstance(x、int)を)行うことができます'または何、これはですが、それはresponse.iため – EdChum

答えて

0

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] 

それともnotnullto_numericによって:

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 

値はintfloatある場合、Seriesすべての値を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'>] 
+0

感謝のようにオブジェクトとデータフレームを読んでいる大規模なデータのために遅くなりますデータ・タイプ 。そのため、この列は一連の文字列として表示されています。浮動小数点型を分離したい場合 – sumi1234

+0

Seriesを文字列として読み込む場合は、数値に変換する必要があります。また、少なくとも1つの浮動小数点値であれば自動的に 'float'に変換されます。または私は何かを逃していますか? – jezrael

+0

これは有用です。また、整数と浮動小数値を別々の2つのリストに分けたいと思っています。 – sumi1234

関連する問題