【发布时间】:2017-06-22 03:18:16
【问题描述】:
我有 pandas DF,它有几个 int type 数据作为字符串和浮点数。
我想将所有可以转换为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.
谢谢,
【问题讨论】:
-
你不能在 pandas 列中使用异构类型,除非你使用
objectdtype。这不是一件好事。
标签: python pandas dataframe lambda int