Skip to content

Commit 6eb4474

Browse files
committed
Test & docs fixups
1 parent 0769cfe commit 6eb4474

File tree

2 files changed

+37
-37
lines changed

2 files changed

+37
-37
lines changed

pandas/core/groupby/generic.py

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2361,43 +2361,43 @@ def value_counts(
23612361
23622362
>>> df.groupby("gender").value_counts()
23632363
gender education country
2364-
female high FR 1
2365-
US 1
2364+
female high US 1
2365+
FR 1
23662366
male low FR 2
23672367
US 1
23682368
medium FR 1
23692369
Name: count, dtype: int64
23702370
23712371
>>> df.groupby("gender").value_counts(ascending=True)
23722372
gender education country
2373-
female high FR 1
2374-
US 1
2373+
female high US 1
2374+
FR 1
23752375
male low US 1
23762376
medium FR 1
23772377
low FR 2
23782378
Name: count, dtype: int64
23792379
23802380
>>> df.groupby("gender").value_counts(normalize=True)
23812381
gender education country
2382-
female high FR 0.50
2383-
US 0.50
2382+
female high US 0.50
2383+
FR 0.50
23842384
male low FR 0.50
23852385
US 0.25
23862386
medium FR 0.25
23872387
Name: proportion, dtype: float64
23882388
23892389
>>> df.groupby("gender", as_index=False).value_counts()
23902390
gender education country count
2391-
0 female high FR 1
2392-
1 female high US 1
2391+
0 female high US 1
2392+
1 female high FR 1
23932393
2 male low FR 2
23942394
3 male low US 1
23952395
4 male medium FR 1
23962396
23972397
>>> df.groupby("gender", as_index=False).value_counts(normalize=True)
23982398
gender education country proportion
2399-
0 female high FR 0.50
2400-
1 female high US 0.50
2399+
0 female high US 0.50
2400+
1 female high FR 0.50
24012401
2 male low FR 0.50
24022402
3 male low US 0.25
24032403
4 male medium FR 0.25

pandas/tests/groupby/methods/test_value_counts.py

Lines changed: 27 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -257,10 +257,10 @@ def test_basic(education_df, request):
257257
index=MultiIndex.from_tuples(
258258
[
259259
("FR", "male", "low"),
260-
("FR", "female", "high"),
261260
("FR", "male", "medium"),
262-
("US", "female", "high"),
261+
("FR", "female", "high"),
263262
("US", "male", "low"),
263+
("US", "female", "high"),
264264
],
265265
names=["country", "gender", "education"],
266266
),
@@ -480,7 +480,7 @@ def test_data_frame_value_counts(
480480
(
481481
False,
482482
False,
483-
[0, 1, 3, 5, 7, 6, 8, 2, 4],
483+
[0, 1, 3, 5, 6, 7, 8, 2, 4],
484484
[0.5, 0.5, 1.0, 0.25, 0.25, 0.25, 0.25, 1.0, 1.0],
485485
),
486486
(False, True, [0, 1, 3, 5, 2, 4], [0.5, 0.5, 1.0, 1.0, 1.0, 1.0]),
@@ -617,17 +617,17 @@ def test_categorical_single_grouper_with_only_observed_categories(
617617
expected_index = MultiIndex.from_tuples(
618618
[
619619
("FR", "male", "low"),
620-
("FR", "female", "high"),
621620
("FR", "male", "medium"),
621+
("FR", "female", "high"),
622+
("FR", "male", "high"),
622623
("FR", "female", "low"),
623624
("FR", "female", "medium"),
624-
("FR", "male", "high"),
625-
("US", "female", "high"),
626625
("US", "male", "low"),
626+
("US", "female", "high"),
627+
("US", "male", "medium"),
628+
("US", "male", "high"),
627629
("US", "female", "low"),
628630
("US", "female", "medium"),
629-
("US", "male", "high"),
630-
("US", "male", "medium"),
631631
],
632632
names=["country", "gender", "education"],
633633
)
@@ -719,17 +719,17 @@ def test_categorical_single_grouper_observed_true(
719719

720720
expected_index = [
721721
("FR", "male", "low"),
722-
("FR", "female", "high"),
723722
("FR", "male", "medium"),
723+
("FR", "female", "high"),
724+
("FR", "male", "high"),
724725
("FR", "female", "low"),
725726
("FR", "female", "medium"),
726-
("FR", "male", "high"),
727-
("US", "female", "high"),
728727
("US", "male", "low"),
728+
("US", "female", "high"),
729+
("US", "male", "medium"),
730+
("US", "male", "high"),
729731
("US", "female", "low"),
730732
("US", "female", "medium"),
731-
("US", "male", "high"),
732-
("US", "male", "medium"),
733733
]
734734

735735
assert_categorical_single_grouper(
@@ -799,23 +799,23 @@ def test_categorical_single_grouper_observed_false(
799799

800800
expected_index = [
801801
("FR", "male", "low"),
802-
("FR", "female", "high"),
803802
("FR", "male", "medium"),
803+
("FR", "female", "high"),
804+
("FR", "male", "high"),
804805
("FR", "female", "low"),
805806
("FR", "female", "medium"),
806-
("FR", "male", "high"),
807-
("US", "female", "high"),
808807
("US", "male", "low"),
808+
("US", "female", "high"),
809+
("US", "male", "medium"),
810+
("US", "male", "high"),
809811
("US", "female", "low"),
810812
("US", "female", "medium"),
811-
("US", "male", "high"),
812-
("US", "male", "medium"),
813-
("ASIA", "female", "high"),
814-
("ASIA", "female", "low"),
815-
("ASIA", "female", "medium"),
816-
("ASIA", "male", "high"),
817813
("ASIA", "male", "low"),
818814
("ASIA", "male", "medium"),
815+
("ASIA", "male", "high"),
816+
("ASIA", "female", "low"),
817+
("ASIA", "female", "medium"),
818+
("ASIA", "female", "high"),
819819
]
820820

821821
assert_categorical_single_grouper(
@@ -957,17 +957,17 @@ def test_categorical_non_groupers(
957957

958958
expected_index = [
959959
("FR", "male", "low"),
960-
("FR", "female", "high"),
961960
("FR", "male", "medium"),
961+
("FR", "female", "high"),
962+
("FR", "male", "high"),
962963
("FR", "female", "low"),
963964
("FR", "female", "medium"),
964-
("FR", "male", "high"),
965-
("US", "female", "high"),
966965
("US", "male", "low"),
966+
("US", "female", "high"),
967+
("US", "male", "medium"),
968+
("US", "male", "high"),
967969
("US", "female", "low"),
968970
("US", "female", "medium"),
969-
("US", "male", "high"),
970-
("US", "male", "medium"),
971971
]
972972
expected_series = Series(
973973
data=expected_data,

0 commit comments

Comments
 (0)