0
我有一些NaN值的數據,我想用imputer
填充NaN值。Python:使用數據幀上的Imputer處理NaN值索引明智
from sklearn.preprocessing import Imputer
imp = Imputer(missing_values='NaN', strategy='mean', axis=1)
cleaned_data = imp.fit_transform(original_data)
到目前爲止,我知道對整列imputer
是這樣工作的:
Point1 Point2
S.No
2 NaN
1 NaN 4
2 NaN
NaN 4
2 2 NaN
NaN 4
應用imputer數據後的樣子:
Point1 Point2
S.No
2 2
1 1 4
2 2
1 4
2 2 2
1 4
,但我想imputer工作指數明智名S.No
Point1 Point2
S.No
2 1.33
1 1.333 4
2 1.33
0.667 4
2 2 2.667
0.667 4
像這樣或不可以實現imputer
或者在DataFrame
上有python
這樣的替代方法。
什麼是'S.No'在這裏?指數?而且我似乎無法重現你的結果。你的數據幀是熊貓數據幀嗎? – Psidom
我導入我的數據像這樣data = pd.read_csv(「filename.csv」,index_col = [0]);是!! 'S.No'是索引,是的!我的數據框是熊貓數據框 –
當我運行你的推算變換時,Point1列被填充4而不是1.也許你想設置'axis = 1'? – Psidom