This file contains 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 os | |
import pandas as pd | |
import matplotlib.pyplot as plt | |
import seaborn as sns | |
import us # pip install us | |
# Data is available here: https://covidtracking.com/data/download | |
df = pd.read_csv(os.path.expanduser('~/Downloads/daily.csv')) | |
# Filter the data, rename stuff |
This file contains 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
"""Static Matplotlib Figures in Flask - Tutorial | |
To run: | |
1. Copy this file. | |
2. Make sure the dependencies are installed (see after the docstring) | |
3. Run in the command line: >>> python mpl_in_flask.py | |
4. Fire up your browser and view the site (default: http://127.0.0.1:5000/) | |
If you want to implement this solution: |
This file contains 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
"""This module makes a class look like a function. The function is stored in | |
``self._func,`` and (most of) the function's properties are exposed in the | |
class's top-level. The biggest issue with the mixin is that ``__call__`` hides | |
the signature of the original function; I'm not sure how to address that. | |
""" | |
def _create_getter_and_setter(name: str): | |
def getter(self): | |
return getattr(self._func, name) |
This file contains 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
"""Run this file like this: | |
>>> python jinja_cli.py path/to/my/file.txt --foo bar | |
and it will render the file as a Jinja template with foo="bar". | |
""" | |
import os | |
import click # pip install click | |
import jinja2 # pip install jinja2 |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains 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 pandas as pd | |
def analyze_data(df: pd.DataFrame): | |
"""This function lets the data speak for itself.""" | |
print(df) |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains 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 numpy as np | |
np.set_printoptions(suppress=True) | |
stdevs = [i / 2 for i in range(1, 24 + 1)] | |
TRIALS = 1_000 | |
WOMEN = 500_000 | |
trial_results = {k: list() for k in stdevs} |