Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit e735412

Browse files
authoredDec 11, 2023
docs: add example to dataframe.nlargest, dataframe.nsmallest, datafra… (#234)
* docs: add example to dataframe.nlargest, dataframe.nsmallest, dataframe.idxmin, dataframe .idxmax * update example output
1 parent 8c63697 commit e735412

File tree

1 file changed

+147
-4
lines changed
  • third_party/bigframes_vendored/pandas/core

1 file changed

+147
-4
lines changed
 

‎third_party/bigframes_vendored/pandas/core/frame.py

+147-4
Original file line numberDiff line numberDiff line change
@@ -3324,6 +3324,58 @@ def nlargest(self, n: int, columns, keep: str = "first"):
33243324
``df.sort_values(columns, ascending=False).head(n)``, but more
33253325
performant.
33263326
3327+
**Examples:**
3328+
3329+
>>> import bigframes.pandas as bpd
3330+
>>> bpd.options.display.progress_bar = None
3331+
3332+
>>> df = bpd.DataFrame({"A": [1, 1, 3, 3, 5, 5],
3333+
... "B": [5, 6, 3, 4, 1, 2],
3334+
... "C": ['a', 'b', 'a', 'b', 'a', 'b']})
3335+
>>> df
3336+
A B C
3337+
0 1 5 a
3338+
1 1 6 b
3339+
2 3 3 a
3340+
3 3 4 b
3341+
4 5 1 a
3342+
5 5 2 b
3343+
<BLANKLINE>
3344+
[6 rows x 3 columns]
3345+
3346+
Returns rows with the largest value in 'A', including all ties:
3347+
3348+
>>> df.nlargest(1, 'A', keep = "all")
3349+
A B C
3350+
4 5 1 a
3351+
5 5 2 b
3352+
<BLANKLINE>
3353+
[2 rows x 3 columns]
3354+
3355+
Returns the first row with the largest value in 'A', default behavior in case of ties:
3356+
3357+
>>> df.nlargest(1, 'A')
3358+
A B C
3359+
4 5 1 a
3360+
<BLANKLINE>
3361+
[1 rows x 3 columns]
3362+
3363+
Returns the last row with the largest value in 'A' in case of ties:
3364+
3365+
>>> df.nlargest(1, 'A', keep = "last")
3366+
A B C
3367+
5 5 2 b
3368+
<BLANKLINE>
3369+
[1 rows x 3 columns]
3370+
3371+
Returns the row with the largest combined values in both 'A' and 'C':
3372+
3373+
>>> df.nlargest(1, ['A', 'C'])
3374+
A B C
3375+
5 5 2 b
3376+
<BLANKLINE>
3377+
[1 rows x 3 columns]
3378+
33273379
Args:
33283380
n (int):
33293381
Number of rows to return.
@@ -3359,6 +3411,59 @@ def nsmallest(self, n: int, columns, keep: str = "first"):
33593411
``df.sort_values(columns, ascending=True).head(n)``, but more
33603412
performant.
33613413
3414+
**Examples:**
3415+
3416+
>>> import bigframes.pandas as bpd
3417+
>>> bpd.options.display.progress_bar = None
3418+
3419+
>>> df = bpd.DataFrame({"A": [1, 1, 3, 3, 5, 5],
3420+
... "B": [5, 6, 3, 4, 1, 2],
3421+
... "C": ['a', 'b', 'a', 'b', 'a', 'b']})
3422+
>>> df
3423+
A B C
3424+
0 1 5 a
3425+
1 1 6 b
3426+
2 3 3 a
3427+
3 3 4 b
3428+
4 5 1 a
3429+
5 5 2 b
3430+
<BLANKLINE>
3431+
[6 rows x 3 columns]
3432+
3433+
Returns rows with the smallest value in 'A', including all ties:
3434+
3435+
>>> df.nsmallest(1, 'A', keep = "all")
3436+
A B C
3437+
0 1 5 a
3438+
1 1 6 b
3439+
<BLANKLINE>
3440+
[2 rows x 3 columns]
3441+
3442+
Returns the first row with the smallest value in 'A', default behavior in case of ties:
3443+
3444+
>>> df.nsmallest(1, 'A')
3445+
A B C
3446+
0 1 5 a
3447+
<BLANKLINE>
3448+
[1 rows x 3 columns]
3449+
3450+
Returns the last row with the smallest value in 'A' in case of ties:
3451+
3452+
>>> df.nsmallest(1, 'A', keep = "last")
3453+
A B C
3454+
1 1 6 b
3455+
<BLANKLINE>
3456+
[1 rows x 3 columns]
3457+
3458+
Returns rows with the smallest values in 'A' and 'C'
3459+
3460+
>>> df.nsmallest(1, ['A', 'C'])
3461+
A B C
3462+
0 1 5 a
3463+
<BLANKLINE>
3464+
[1 rows x 3 columns]
3465+
3466+
33623467
Args:
33633468
n (int):
33643469
Number of rows to return.
@@ -3384,23 +3489,61 @@ def nsmallest(self, n: int, columns, keep: str = "first"):
33843489

33853490
def idxmin(self):
33863491
"""
3387-
Return index of first occurrence of minimum over requested axis.
3492+
Return index of first occurrence of minimum over columns.
33883493
33893494
NA/null values are excluded.
33903495
3496+
**Examples:**
3497+
3498+
>>> import bigframes.pandas as bpd
3499+
>>> bpd.options.display.progress_bar = None
3500+
3501+
>>> df = bpd.DataFrame({"A": [3, 1, 2], "B": [1, 2, 3]})
3502+
>>> df
3503+
A B
3504+
0 3 1
3505+
1 1 2
3506+
2 2 3
3507+
<BLANKLINE>
3508+
[3 rows x 2 columns]
3509+
3510+
>>> df.idxmin()
3511+
A 1
3512+
B 0
3513+
dtype: Int64
3514+
33913515
Returns:
3392-
Series: Indexes of minima along the specified axis.
3516+
Series: Indexes of minima along the columns.
33933517
"""
33943518
raise NotImplementedError(constants.ABSTRACT_METHOD_ERROR_MESSAGE)
33953519

33963520
def idxmax(self):
33973521
"""
3398-
Return index of first occurrence of maximum over requested axis.
3522+
Return index of first occurrence of maximum over columns.
33993523
34003524
NA/null values are excluded.
34013525
3526+
**Examples:**
3527+
3528+
>>> import bigframes.pandas as bpd
3529+
>>> bpd.options.display.progress_bar = None
3530+
3531+
>>> df = bpd.DataFrame({"A": [3, 1, 2], "B": [1, 2, 3]})
3532+
>>> df
3533+
A B
3534+
0 3 1
3535+
1 1 2
3536+
2 2 3
3537+
<BLANKLINE>
3538+
[3 rows x 2 columns]
3539+
3540+
>>> df.idxmax()
3541+
A 0
3542+
B 2
3543+
dtype: Int64
3544+
34023545
Returns:
3403-
Series: Indexes of maxima along the specified axis.
3546+
Series: Indexes of maxima along the columns.
34043547
"""
34053548
raise NotImplementedError(constants.ABSTRACT_METHOD_ERROR_MESSAGE)
34063549

0 commit comments

Comments
 (0)
Failed to load comments.