Masking sensitive data
Security and privacy are crucial when working with data. There is some data that only certain people are allowed to see, such as your social security number, driver’s license number, and medical records. This data should be treated with care and be protected appropriately.
The best scenario is that you don’t store these kinds of data, or the process of masking data has been taken care of before the data gets to you. However, it’s always good to know how to work with and hide this kind of information. There are some ways you can mask your data, including replacing or randomizing values, hashing, and encryption.
In this recipe, we’ll cover how to mask our data by replacing values as well as hashing them.
How to do it...
Here is how to mask sensitive data:
- Create a column called
SSN
(which stands for social security number).- Create a function to generate random numbers:
import random def get_random_nums(num_list, length...