Created
June 25, 2018 15:53
-
-
Save crawles/859b2563a8f4d392c004f00e26856155 to your computer and use it in GitHub Desktop.
drop random elements from a pandas dataframe
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def random_null(col, keep=0.9): | |
import random | |
if keep < random.random(): | |
return None | |
return col | |
df.applymap(lambda x: random_null(x)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment