Python으로 배우는 데이터 프라이버시와 익명화
Rebeca Gonzalez
Data engineer
비민감 개인식별정보도 준식별자가 될 수 있습니다.

다른 준식별자와 결합되면 식별이 가능합니다.


데이터 공개 위험을 줄이는 준식별자 익명화 기법.

원본 DataFrame
name phone
0 Cassandra Nelson 4399406975395
1 Brian Moss 0389407128613
2 Melody Gill 8283308773967
3 Sandra Huber 4366608954250
4 Patricia Webster 4466462475574
이름이 마스킹된 DataFrame
name phone
0 xxxx 4399406975395
1 xxxx 0389407128613
2 xxxx 8283308773967
3 xxxx 4366608954250
4 xxxx 4466462475574
민감 값을 "x"와 같은 문자로 대체하는 것을 데이터 마스킹이라 합니다.
# DataFrame 살펴보기
df.head()
country card_number email
0 Finland 3546746666030419 [email protected]
1 Belarus 4303032415762821 [email protected]
2 Turkmenistan 4536883671157 [email protected]
3 Puerto Rico 3568819286614160 [email protected]
4 Angola 2514167462583016 [email protected]
# 카드 번호 열을 일괄 마스킹 df['card_number'] = '****'# 결과 DataFrame 확인 df.head()
country card_number email
0 Finland **** [email protected]
1 Belarus **** [email protected]
2 Turkmenistan **** [email protected]
3 Puerto Rico **** [email protected]
4 Angola **** [email protected]

# 이메일에서 사용자명 마스킹 df2['email'] = df2['email'].apply(lambda s: s[0] + '****' + s[s.find('@'):] )# 결과 가명처리 데이터 확인 df2.head()
country card_number email
0 Finland 3546746666030419 f****@gmail.com
1 Belarus 4303032415762821 m****@gmail.com
2 Turkmenistan 4536883671157 a****@gmail.com
3 Puerto Rico 3568819286614160 k****@gmail.com
4 Angola 2514167462583016 d****@gmail.com

# Faker 클래스 임포트 from faker import Faker# 가짜 데이터 생성기 만들기 fake_data = Faker()# 신용카드 번호 생성 fake_data.credit_card_number()
3542216874440804
# 람다로 새 데이터로 카드 번호 마스킹 df['card_number'] = df['card_number'].apply(lambda x: fake_data.credit_card_number())# 결과 가명처리 데이터 확인 df.head()
country card_number email
0 Finland 3596625386355448 [email protected]
1 Belarus 376297265347524 [email protected]
2 Turkmenistan 4377494880888682 [email protected]
3 Puerto Rico 30553931809810 [email protected]
4 Angola 4241735748382 [email protected]
fake_data.name()
'Kelly Clark'
fake_data.name_male()
'Antonio Henderson'
fake_data.name_female()
'Jennifer Ortega'
Python으로 배우는 데이터 프라이버시와 익명화