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 compound(initial, percent, years): | |
| if years>0: | |
| initial+=(initial*percent) | |
| years-=1 | |
| return compound(initial, percent, years) | |
| else: | |
| return initial |
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 datetime | |
| import pytz | |
| import dateutil | |
| import os | |
| def datetime_to_str(datetime_obj, date_format="%Y_%m_%d_%H_%M_%S"): | |
| """Convert a `datetime.datetime` object to a string in the desired format. | |
| Reference for string formatting dates available here: | |
| http://strftime.org/ |
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)) |
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
| // I always forget this so saving it here; taken from: | |
| // http://chris-said.io/2016/02/13/how-to-make-polished-jupyter-presentations-with-optional-code-visibility/ | |
| // This script hides the code and leaves a button to toggle it on/off: | |
| <script> | |
| function code_toggle() { | |
| if (code_shown){ | |
| $('div.input').hide('500'); | |
| $('#toggleButton').val('Show Code') | |
| } else { |
NewerOlder