【问题标题】:Create column from non null values in other column in Pandas从 Pandas 中其他列中的非空值创建列
【发布时间】:2015-07-16 16:17:30
【问题描述】:

我在 pandas 数据框中有一列包含一些整数和一些空值。如何用另一列(同一行)中的浮点值替换整数,但保留所有空值?

【问题讨论】:

    标签: python pandas dataframe


    【解决方案1】:

    需要确切的列和 df 来确定,但你可以试试这个:

    df.loc[df['ints'].notnull(),'ints'] = df['floats']
    

    其中 df 是您的数据框,ints 是整数列,floats 是浮点列。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-01-21
      • 1970-01-01
      • 1970-01-01
      • 2020-09-24
      • 2020-07-06
      相关资源
      最近更新 更多