2017-06-22 1 views
0

私はいくつかの文字列と浮動小数点としてのデータを持っているパンダDFを持っています。 intに変換できるすべてのデータをそのままintとして残しておきます。pandasのすべてのint convertibleデータをintに変換するには?

# something like 
df = df.applymap(lambda x: int(x) if type(int(x)) is int else x) 

# this code is wrong and is something like x/y problem. But, is there a easy way workout this problem. 

おかげで、

+1

あなたは 'object' DTYPEを使用しない限りあなたは、パンダの列にhetergenousタイプを持つことはできません。それは良いことではありません。 –

答えて

-1

あなたは(isdigitを使用することができます)

df.applymap(lambda x: 'int' if str(x).isdigit() else x) 
+1

問題:「-10」、「0x1234」、「1e10」 –

関連する問題