【问题标题】:How to use replace for multiple columns in one go [duplicate]如何一次性使用替换多个列[重复]
【发布时间】:2021-11-27 01:41:04
【问题描述】:

我正在尝试一次性替换所有数据集列的“%”。

df["Delhi"] = df.Delhi.apply(lambda x :x.replace("%",""))

设法更新单个列,现在希望避免对所有列一次又一次地重复相同的功能。有没有一次性完成的功能或方法?

【问题讨论】:

    标签: python-3.x pandas dataframe numpy


    【解决方案1】:

    遍历列:

    for column in df.columns:
        df[column] = df[column].str.replace("%","")
    

    一站式完成

    df.replace("%", "", regex=True)
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2020-10-07
      • 2023-03-17
      • 2011-03-18
      • 2019-05-20
      • 2011-10-22
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多