다음과 같은 Dataframe이 있습니다.
prod_id, prod_name, col_1, col_2, type
101, electronic, 10, 10, old
102, hardware, 2, 4, old
101, electronic, 10, 10, new
102, hardware, 2, 1, new
103, other, 22, 13, new
type=old
다른 모든 열이 값을 사용하여 동일한 경우 업데이트 된 데이터 프레임에 행이 있도록 데이터 프레임을 업데이트하려고합니다.type=new
최종 출력 :
prod_id, prod_name, col_1, col_2, type
101, electronic, 10, 10, old
102, hardware, 2, 1, new
103, other, 22, 13, new
내가 이해 한 바에 따르면, 중복 된 값이없고 유형이 새로운 지 확인하고 중복이있을 때 유형 = '이전'을 유지하는 두 개의 부울 마스크로 시도합니다.
u = df.drop("type",1)
c = ((u.duplicated(keep=False) & df['type'].eq('old')) |
(df['type'].eq('new') & ~u.duplicated(keep=False)) )
out = df[c].copy()
prod_id prod_name col_1 col_2 type
0 101 electronic 10 10 old
3 102 hardware 2 1 new
4 103 other 22 13 new
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다