2017-04-18 4 views
1

python pandas standardize column for regression 내 dataframe에서 특정 열을 스케일링 오전에 ValueError를 인상되므로 1 차원 배열을 전달 불행하게도 파이썬 DeprecationWarning : 데이터가 0.17에서 사용되지 않으며로 내 앞의 질문을 바탕으로 0.19

scaler = preprocessing.MinMaxScaler(feature_range=(0,1)) 
email['scaled_quantity'] = scaler.fit_transform(email['Quantity']) 

0과 1 이 오류가 발생합니다.

DeprecationWarning: Passing 1d arrays as data is deprecated in 0.17 and will raise ValueError in 0.19. Reshape your data either using X.reshape(-1, 1) if your data has a single feature or X.reshape(1, -1) if it contains a single sample. 
    warnings.warn(DEPRECATION_MSG_1D, DeprecationWarning) 

@Grr이 전체 데이터 프레임에 스케일링을 적용한다고 제안되었지만 이는 옵션이 아닙니다. 열을 유지하는 방식으로 새로운 열을 추가해야합니다.

어떻게 감가 상각 오류를 해결할 수 있습니까?

답변

5

무엇

scaler.fit_transform(email['Quantity']) 

데모

scaler.fit_transform(email[['Quantity']]) 

대신하기에 관하여 : 당신의 샘플 데이터가 이전 질문에서 설정 사용 :

In [56]: scaler.fit_transform(df[['Event_Counts']]) 
Out[56]: 
array([[ 0.99722347], 
     [ 1.  ], 
     [ 0.  ]]) 

공지 사항 - 그것은 생산 (3,1) 대신에 모양이 배열 인 배열 (3,) 새 열로

:

In [58]: df['scaled_event_counts'] = scaler.fit_transform(df[['Event_Counts']]) 

In [59]: df 
Out[59]: 
     Date Event_Counts Category_A Category_B scaled_event_counts 
0 20170401  982457   0   1    0.997223 
1 20170402  982754   1   0    1.000000 
2 20170402  875786   0   1    0.000000 
+0

당신을 감사합니다; 차이점을 설명해 주시겠습니까? – jeangelj

+0

그것은 일했다; 매우 고마워요 – jeangelj

+0

@ jeangelj, 당신은 환영합니다 – MaxU