Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@jaymody
Last active April 4, 2021 22:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jaymody/cf55a5b94d56fffe24cbcce142c1f7d6 to your computer and use it in GitHub Desktop.
Save jaymody/cf55a5b94d56fffe24cbcce142c1f7d6 to your computer and use it in GitHub Desktop.
import statistics
import seaborn as sns
import matplotlib.pyplot as plt
def stats(values, plot=False):
# statistics.mode throws an error if there are multiple modes
try:
mode = statistics.mode(values)
except:
mode = None
d = {
"len": len(values),
"max": max(values),
"min": min(values),
"mean": statistics.mean(values),
"median": statistics.median(values),
"mode": mode,
"stdev": statistics.stdev(values),
}
if plot:
sns.distplot(values)
plt.show()
return d
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment