用列中的零百分比替换零小于50

时间:2019-10-21 17:45:06

标签: python pandas loops

我正在尝试创建一个评估者。如果一列中的零百分比小于50%,则用均值替换零。

我尝试了所有我无法想到的东西,但是没有任何效果。

class Manager : public Employee, public Student {
   ...
};
let base_price = 149.99;
if(sqft > 2000){
   let overage = sqft - 2000;
   let percentage = Math.ceil(overage % 500) * 10;
   base_price += base_price * percentage;
}

2 个答案:

答案 0 :(得分:0)

尝试一下:

i = 0
if df[i].value_counts()[0] / len(df) < 0.5:
    df.iloc[df['i'] == 0, i] = df[i].mean()

答案 1 :(得分:0)

exclude = ['c', 'f']

def Zeros(i):
    while i < len(df1.columns):
        if df1.columns[i] in exclude:
            i = i+1
        elif (1-((df1.iloc[:, i] == 0).astype(float).sum(axis=0)/df1.iloc[:, i].count())) > 0.5:    
            df1.iloc[:, i] = df1.iloc[:, i].mask(df1.iloc[:, i]==0).fillna(df1.iloc[:, i].mean())              
            i = i+1
        else:
            i = i+1
    return
Zeros(0)