2017-06-22 152 views
0

我有熊猫DF,它有几个int type数据作为字符串和浮点数。 我想将所有可以转换为int的数据转换为int,否则保持原样。如何在熊猫中将所有int转换数据转换为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

你不能有hetergenous类型的大熊猫列,除非你用'object' D型。这不是一件好事。 –

回答

-1

您可以使用ISDIGIT()

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

有问题:“-10”,“0x1234”,“1e10” –