在 Pandas 数据帧 python 中使用 pii 匿名化特定列 [英] Anonymize specific columns with pii in pandas dataframe python

查看:57
本文介绍了在 Pandas 数据帧 python 中使用 pii 匿名化特定列的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经加载了一个带有 json 文件的 s3 存储桶,并将其解析/展平为一个 Pandas 数据帧.现在我有一个包含 175 列的数据框,其中 4 列包含个人身份信息.

I have loaded an s3 bucket with json files and parsed/flattened it in to a pandas dataframe. Now i have a dataframe with 175 columns with 4 columns containing personally identifiable information.

我正在寻找一种快速解决方案,将这些列(名称和地址)匿名化.我需要保留多个信息,以便同一个人的姓名或地址多次出现时具有相同的哈希值.

I am looking for a quick solution anonymising those columns (name & adress). I need to keep information for multiples so that if names or adresses of the same person occuring multiple times have the same hash.

pandas 或其他一些包中是否有可用的功能?

Is there existing functionality in pandas or some other package i can utilize for this?

推荐答案

使用 Categorical 将是一种有效的方法 - 主要警告是编号将仅基于排序在数据中,因此如果需要跨多个列/数据集使用此编号方案,则需要小心.

Using a Categorical would be an efficient way to do this - the main caveat is that the numbering will be based solely on the ordering in the data, so some care will be needed if this numbering scheme needs to be used across multiple columns / datasets.

df = pd.DataFrame({'ssn': [1, 2, 3, 999, 10, 1]})

df['ssn_anon'] = df['ssn'].astype('category').cat.codes

df
Out[38]: 
   ssn  ssn_anon
0    1         0
1    2         1
2    3         2
3  999         4
4   10         3
5    1         0

这篇关于在 Pandas 数据帧 python 中使用 pii 匿名化特定列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆