如何将pandas数据框中的特定行乘以条件

I have a column which of 10th marks but some specific rows are not scaled properly i.e they are out of 10. I want to create a function that will help me to detect which are <=10 and then multiply to 100. I tried by creating a function but it failed. Following is the Column: data['10th']

0           0
1           0
2           0
3       10.00
4           0
        ...  
2163        0
2164        0
2165        0
2166    76.50
2167    64.60
Name: 10th, Length: 2168, dtype: object
评论
BOX07
BOX07

我不是“乘以100”是什么意思,但是您应该可以将lambda与apply一起使用,例如:

df = pd.DataFrame({"a": [1, 3, 5, 23, 76, 43 ,12, 3 ,5]})
df['a'] = df['a'].apply(lambda x: x*100 if x < 10 else x)
print(df)

0   100
1   300
2   500
3   23
4   76
5   43
6   12
7   300
8   500

如果我对您的理解不正确,则可以按照自己的目的替换lambda函数中的操作和条件。

点赞
评论