-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathstatsfun.py
More file actions
59 lines (45 loc) · 1.44 KB
/
statsfun.py
File metadata and controls
59 lines (45 loc) · 1.44 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on Sat Apr 18 17:57:28 2020
@author: StatsGnewt
Using some support for type hints
https://docs.python.org/3/library/typing.html
"""
from typing import Sequence
import pandas as pd
from itertools import product
from math import factorial, sqrt
from random import shuffle
def deck_of_cards(shuffled = True):
face_cards = ['Ace', 'King', 'Queen', 'Jack']
numb_cards = [str(i) for i in range(2, 11)]
suits = ['Hearts', 'Diamonds', 'Spades', 'Clubs']
# match every card with every suit
cards = list(product(face_cards + numb_cards, suits))
if shuffled:
shuffle(cards)
return cards
def mean(iterable : Sequence) -> float:
return sum(iterable)/len(iterable)
def var(iterable : Sequence) -> float:
av = mean(iterable)
return sum([(x - av)**2 for x in iterable])/len(iterable)
def std(iterable : Sequence) -> float:
return sqrt(var(iterable))
def choose(n, k):
return factorial(n)//(factorial(k)*factorial(n-k))
def sum_binom(n, x):
return sum(choose(n,k) * x**k for k in range(0, n+1))
def pascal(n):
return [choose(n,k) for k in range(0,n+1)]
def pascal_gen():
row = [1]
while True:
yield row
row = [i+j for i, j in zip(row + [0], [0] + row)]
def get_coasters():
coasters = pd.read_csv("./data/roller_coasters.csv")
return coasters
def z_score(x, mu, sigma, n=1):
return (x - mu)/(sigma/sqrt(n))