Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
410 changes: 410 additions & 0 deletions BekksRoom/dictionary.csv

Large diffs are not rendered by default.

31 changes: 31 additions & 0 deletions BekksRoom/dictionary.py

Large diffs are not rendered by default.

139 changes: 139 additions & 0 deletions BekksRoom/messy.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,139 @@
from BekksRoom.stats_functions import average_minutes, stdev_minutes
from BekksRoom.stats_functions import hypothesis_test_plot
import pandas as pd
import matplotlib as plt


def get_input(dataset):
done = False
std = 'n'
avg = 'n'
hypothesis = 'n'
going_to_use_groupby = 'n'
avg = input("want the average? y/n ")
clean = input("Want your data cleaned? We drop zeros and nan. y/n ")
columns = []
if avg == "y":
print("Automatically including weight because you want the average")
columns.append('weight')
else:
std = input("Want standard Deviation? y/n ")
if std == 'y':
print("Automatically including weight because you want the standard dev")
columns.append('weight')
if avg != 'y' or std != 'y':
hypothesis = input("Want hypothesis testing? y/n ")
if hypothesis == 'y':
print("Automatically including weight because you want hypothesis test")
columns.append('weight')
if avg != 'y' and std != 'y' and hypothesis != 'y':
going_to_use_groupby = input("Are you going to use groupby? y/n ")
if going_to_use_groupby == 'y':
print("Automatically including weight because you want to use groupby ")
columns.append('weight')
for item in dataset.columns.tolist():
print(item)
while not done:
print("Enter you column as appears above, type DONE when done, or CLEAR if you messup")
column = input("What columns do you want?")
if column == 'DONE':
done = True
break
if column == 'CLEAR':
columns = []
if column in dataset.columns.tolist():
columns.append(column)
else:
print("Not in dataset")
print(columns)
return(avg, clean, columns, std, hypothesis, going_to_use_groupby)


def querys(datawork, query):
return datawork[query]


def graph_data(dataset):
wplot = input("What type of plot? bar or line (more to come)")
if wplot == "bar":
print(plt.style.available)
plot_style = input("What style plot? Type it correctly!")
plt.style.use(plot_style)
print("Your data sir ", dataset)
figuresize = input("Whats your figure size, just enter one number no floats")
figuresize = int(figuresize)
legends = input("Want a legend True/False")
stacks = input("Want to stack it? True/False")
xlabels = input("x label?")
ylabels = input("y label?")
grids = input("Want a grid True/False")
ax = dataset.plot(kind="bar", figsize=(figuresize,figuresize), legend=eval(legends), stacked=eval(stacks))
ax.set_ylabel(ylabels)
ax.grid(eval(grids), 'both')
ax.set_xlabel(xlabels)
return ax
if wplot == "line":
print(plt.style.available)
plot_style = input("What style plot? Type it correctly!")
plt.style.use(plot_style)
print("Your data sir ", dataset)
figuresize = input("Whats your figure size, just enter one number no floats")
figuresize = int(figuresize)
legends = input("Want a legend True/False")
xlabels = input("x label?")
ylabels = input("y label?")
grids = input("Want a grid True/False")
ax = dataset.plot(kind="line", figsize=(figuresize,figuresize), legend=eval(legends))
ax.set_ylabel(ylabels)
ax.grid(eval(grids), 'both')
ax.set_xlabel(xlabels)
return ax


def datasets(dataset, query=None):
avg, clean, columns, std, hypothesis, going_to_use_groupby = get_input(dataset)
# print(avg, clean, columns)
data = dataset[columns]
if query is not None:
data = querys(data, query)
data.describe()
if std == 'y':
newdataframe = {}
for item in data.columns.tolist():
if item == "weight":
pass
else:
newdataframe[item] = [stdev_minutes(data, item)]
data = pd.DataFrame.from_dict(newdataframe, orient='columns', dtype=None)
if avg == 'y':
newdataframe = {}
for item in data.columns.tolist():
if item == "weight":
pass
else:
newdataframe[item] = [average_minutes(data, item)]
data = pd.DataFrame.from_dict(newdataframe, orient='columns', dtype=None)
if clean == 'y':
for item in data.columns.tolist():
if item == "weight":
pass
else:
data = data[data[item] > 0]
data = data.dropna()
# print(data)
if going_to_use_groupby == 'y':
while True:
column_to_group = input("What column would you like to group by? ")
if column_to_group in data:
return data.groupby(column_to_group)
else:
print("Thats not in your columns")
if hypothesis == 'y':
group_var = input("What is your group variable?")
test_var = input("What is your test variable?")
data = hypothesis_test_plot(data, group_var, test_var)
graphs = input("Want to graph your data? y/n")
if graphs == 'y':
plot = graph_data(data)
return(data, plot)
return data
38 changes: 38 additions & 0 deletions BekksRoom/stats_functions.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import math
import pandas as pd


def average_minutes(data, activity_col, weight_col="weight"):
data = data.rename(columns={weight_col: "weight",
activity_col: "minutes"})
data = data[['weight', "minutes"]]
data['weighted_minutes'] = data.weight * data.minutes
return data.weighted_minutes.sum() / data.weight.sum()


def stdev_minutes(data, activity_col, weight_col="weight"):
data_mean = average_minutes(data, activity_col, weight_col)
data = data.rename(columns={weight_col: "weight",
activity_col: "minutes"})
num_non0_obs = data[data.weight != 0].weight.count()
data = data[["weight", "minutes"]]
data['weighted_ss'] = data.weight * (data.minutes - data_mean)**2
return math.sqrt(data.weighted_ss.sum() /
(((num_non0_obs-1)/num_non0_obs)*data.weight.sum()))


def hypothesis_test_plot(data, group_var, test_var, weight_var="weight"):
data = data[[group_var, test_var, weight_var]]
data_grouped = data.groupby(group_var)
frame = pd.DataFrame()
for group in data_grouped:
count = group[1][weight_var].count()
mean = average_minutes(group[1], test_var, weight_var)
stdev = stdev_minutes(group[1], test_var, weight_var)
frame = frame.append({group_var: group[0],
"mean": mean,
"error": (stdev*1.96/math.sqrt(count))},
ignore_index=True)
frame.index = frame.pop(group_var)
plot = frame.plot(kind="bar", yerr="error", figsize=(12, 8))
return (frame, plot)
Loading