Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add x and y medians to plot #188

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
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
7 changes: 5 additions & 2 deletions src/data_morph/data/stats.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
import pandas as pd

SummaryStatistics = namedtuple(
'SummaryStatistics', ['x_mean', 'y_mean', 'x_stdev', 'y_stdev', 'correlation']
'SummaryStatistics',
['x_mean', 'y_mean', 'x_med', 'y_med', 'x_stdev', 'y_stdev', 'correlation'],
)
SummaryStatistics.__doc__ = (
'Named tuple containing the summary statistics for plotting/analysis.'
Expand All @@ -24,12 +25,14 @@ def get_values(df: pd.DataFrame) -> SummaryStatistics:
Returns
-------
SummaryStatistics
Named tuple consisting of mean and standard deviations of x and y,
Named tuple consisting of mean, median and standard deviations of x and y,
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I much prefer Oxford commas, so let's change this to this:

Suggested change
Named tuple consisting of mean, median and standard deviations of x and y,
Named tuple consisting of mean, median, and standard deviations of x and y,

along with the Pearson correlation coefficient between the two.
"""
return SummaryStatistics(
df.x.mean(),
df.y.mean(),
df.x.median(),
df.y.median(),
df.x.std(),
df.y.std(),
df.corr().x.y,
Expand Down
2 changes: 1 addition & 1 deletion src/data_morph/plotting/static.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ def plot(

res = get_values(df)

labels = ('X Mean', 'Y Mean', 'X SD', 'Y SD', 'Corr.')
labels = ('X Mean', 'Y Mean', 'X Med.', 'Y Med.', 'X SD', 'Y SD', 'Corr.')
locs = np.linspace(0.8, 0.2, num=len(labels))
max_label_length = max([len(label) for label in labels])
max_stat = int(np.log10(np.max(np.abs(res)))) + 1
Expand Down
2 changes: 2 additions & 0 deletions tests/data/test_stats.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ def test_stats():

assert stats.x_mean == data.x.mean()
assert stats.y_mean == data.y.mean()
assert stats.x_med == data.x.median()
assert stats.y_med == data.y.median()
assert stats.x_stdev == data.x.std()
assert stats.y_stdev == data.y.std()
assert stats.correlation == data.corr().x.y
Loading