Last active
March 6, 2019 16:28
-
-
Save toby-p/57ff1ca26a75ca04f7b64f1246633257 to your computer and use it in GitHub Desktop.
Function to generate unique random strings; mainly for use as a temporary column name in 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
| import string | |
| import random | |
| def random_str(l=100): | |
| """Return a random string of length `l` to use as a temporary unique | |
| variable name or Pandas DataFrame column name.""" | |
| s = random.choice(string.ascii_letters) # 1st letter = alpha so can be used as var name. | |
| return s+"".join(random.choice(string.ascii_letters+string.digits) for i in range(l-1)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment