Last active
August 29, 2015 14:21
-
-
Save selwyth/c0de22ca75825b6107b2 to your computer and use it in GitHub Desktop.
Generating different types of data to illustrate examples or create a grid to conform to
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
# http://pandas.pydata.org/pandas-docs/stable/cookbook.html/ bottom example | |
def expand_grid(data_dict): | |
rows = itertools.product(*data_dict.values()) | |
return pd.DataFrame.from_records(rows, columns=data_dict.keys()) | |
df = expand_grid( | |
{'height': [60, 70], | |
'weight': [100, 140, 180], | |
'sex': ['Male', 'Female']}) |
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
from scipy import stats | |
import numpy as np | |
def plot_beta(a, b, res): | |
x = np.linspace(stats.beta.ppf(0.01, a=a, b=b), | |
stats.beta.ppf(0.99, a=a, b=b), res) | |
y = stats.beta.pdf(x, a, b) | |
plt.plot(x, y) | |
def plot_poisson(mu): | |
x = np.linspace(0,10,11) | |
y = stats.poisson.pmf(x, mu=mu) | |
plt.plot(x, y) |
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
# Add months to datetime | |
df['datetime'] + df['months_int'].values.astype('timedelta64[M]') | |
# Create DateTimeIndex | |
df = pd.DataFrame(index=pd.date_range('5/1/2015', periods=5)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment