Skip to content

Instantly share code, notes, and snippets.

@ksomemo
Last active July 24, 2017 02:27
Show Gist options
  • Save ksomemo/efba1e4eafe28298d572 to your computer and use it in GitHub Desktop.
Save ksomemo/efba1e4eafe28298d572 to your computer and use it in GitHub Desktop.
python package での zscore
Display the source blob
Display the rendered blob
Raw
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
import pandas as pd
import numpy as np
import scipy as sp
import seaborn as sns
import matplotlib.pyplot as plt
%matplotlib inline
# pd.stats.misc.zscore AttributeError
df = pd.DataFrame({"n": range(10)})
df = df.assign(
sp_z=sp.stats.zscore(df["n"]),
ddof_t_z=(df["n"] - df["n"].mean()) / df["n"].std(),
ddof_f_z=(df["n"] - df["n"].mean()) / df["n"].std(ddof=False)
)
# degrees of freedom
# http://pandas.pydata.org/pandas-docs/stable/generated/pandas.DataFrame.std.html
print(df.min())
print(df.max())
df.plot(subplots=True, figsize=(10, 4), layout=(1, 4))
plt.tight_layout()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment