我有一個數據框,在列中有響應和預測變量,在行中有觀察值。響應中的某些值低於給定的檢測限(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