【问题标题】:Fill in missing values in DataFrame Column which is incrementing by 10在递增 10 的 DataFrame 列中填写缺失值
【发布时间】:2020-06-29 10:44:58
【问题描述】:

说,“计数”列中的某些值缺失。这些数字意味着每行增加 10,因此需要放置“35”和“55”。我想填写这些缺失值。

         Counts
0        25    
1        NaN
2        45
3        NaN
4        65

所以我的输出应该是:

         Counts
0        25    
1        35
2        45
3        55
4        65

谢谢,

【问题讨论】:

    标签: python-3.x pandas dataframe


    【解决方案1】:

    我们有interpolate

    df=df.interpolate()
       Counts
    0    25.0
    1    35.0
    2    45.0
    3    55.0
    4    65.0
    

    【讨论】:

      【解决方案2】:

      既然你现在是模式,你可以简单地重新创建它:

      start = df.iloc[0]['Counts'] # first row
      end = df.iloc[-1]['Counts'] # last row
      df['Counts'] = np.where(df['Counts'].notnull(), df['Counts'], 
                              np.arange(start, end + 1, 10))
      

      【讨论】:

        猜你喜欢
        • 2017-07-03
        • 2021-12-26
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2017-05-19
        • 2012-01-29
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多