我有一个数据框,在列中有响应和预测变量,在行中有观察值。响应中的某些值低于给定的检测限(LOD)。由于我计划对答复应用排名转换,因此我希望将所有这些值设置为等于LOD。可以说,数据帧是将混合值DataFrame中的特定值设置为固定值?
data.head()
age response1 response2 response3 risk sex smoking
0 33 0.272206 0.358059 0.585652 no female yes
1 38 0.425486 0.675391 0.721062 yes female no
2 20 0.910602 0.200606 0.664955 yes female no
3 38 0.966014 0.584317 0.923788 yes female no
4 27 0.756356 0.550512 0.106534 no female yes
我愿做
responses = ['response1', 'response2', 'response3']
LOD = 0.2
data[responses][data[responses] <= LOD] = LOD
其中有多个原因不工作(如大熊猫不知道是否应该产生对数据的视图或不,它不会,我猜)
我如何在
data[responses] <= LOD
等于LOD设置的所有值?
最少例如:
import numpy as np
import pandas as pd
from pandas import Series, DataFrame
x = Series(random.randint(0,2,50), dtype='category')
x.cat.categories = ['no', 'yes']
y = Series(random.randint(0,2,50), dtype='category')
y.cat.categories = ['no', 'yes']
z = Series(random.randint(0,2,50), dtype='category')
z.cat.categories = ['male', 'female']
a = Series(random.randint(20,60,50), dtype='category')
data = DataFrame({'risk':x, 'smoking':y, 'sex':z,
'response1': random.rand(50),
'response2': random.rand(50),
'response3': random.rand(50),
'age':a})
做'数据[数据[应答] <= LOD] = 0.2' – EdChum