Skip to content

Commit 77074ec

Browse files
authored
docs: add examples for dataframe.nunique, dataframe.diff, dataframe.a… (#251)
* docs: add examples for dataframe.nunique, dataframe.diff, dataframe.agg, dataframe.describe * update spacing * update ordering
1 parent c2829e3 commit 77074ec

File tree

1 file changed

+112
-2
lines changed
  • third_party/bigframes_vendored/pandas/core

1 file changed

+112
-2
lines changed

third_party/bigframes_vendored/pandas/core/frame.py

+112-2
Original file line numberDiff line numberDiff line change
@@ -3434,7 +3434,26 @@ def melt(self, id_vars, value_vars, var_name, value_name):
34343434

34353435
def nunique(self):
34363436
"""
3437-
Count number of distinct elements in specified axis.
3437+
Count number of distinct elements in each column.
3438+
3439+
**Examples:**
3440+
3441+
>>> import bigframes.pandas as bpd
3442+
>>> bpd.options.display.progress_bar = None
3443+
3444+
>>> df = bpd.DataFrame({"A": [3, 1, 2], "B": [1, 2, 2]})
3445+
>>> df
3446+
A B
3447+
0 3 1
3448+
1 1 2
3449+
2 2 2
3450+
<BLANKLINE>
3451+
[3 rows x 2 columns]
3452+
3453+
>>> df.nunique()
3454+
A 3.0
3455+
B 2.0
3456+
dtype: Float64
34383457
34393458
Returns:
34403459
bigframes.series.Series: Series with number of distinct elements.
@@ -3578,6 +3597,40 @@ def diff(
35783597
Calculates the difference of a DataFrame element compared with another
35793598
element in the DataFrame (default is element in previous row).
35803599
3600+
**Examples:**
3601+
3602+
>>> import bigframes.pandas as bpd
3603+
>>> bpd.options.display.progress_bar = None
3604+
3605+
>>> df = bpd.DataFrame({"A": [3, 1, 2], "B": [1, 2, 3]})
3606+
>>> df
3607+
A B
3608+
0 3 1
3609+
1 1 2
3610+
2 2 3
3611+
<BLANKLINE>
3612+
[3 rows x 2 columns]
3613+
3614+
Calculating difference with default periods=1:
3615+
3616+
>>> df.diff()
3617+
A B
3618+
0 <NA> <NA>
3619+
1 -2 1
3620+
2 1 1
3621+
<BLANKLINE>
3622+
[3 rows x 2 columns]
3623+
3624+
Calculating difference with periods=-1:
3625+
3626+
>>> df.diff(periods=-1)
3627+
A B
3628+
0 2 -1
3629+
1 -1 -1
3630+
2 <NA> <NA>
3631+
<BLANKLINE>
3632+
[3 rows x 2 columns]
3633+
35813634
Args:
35823635
periods (int, default 1):
35833636
Periods to shift for calculating difference, accepts negative
@@ -3590,7 +3643,37 @@ def diff(
35903643

35913644
def agg(self, func):
35923645
"""
3593-
Aggregate using one or more operations over the specified axis.
3646+
Aggregate using one or more operations over columns.
3647+
3648+
**Examples:**
3649+
3650+
>>> import bigframes.pandas as bpd
3651+
>>> bpd.options.display.progress_bar = None
3652+
3653+
>>> df = bpd.DataFrame({"A": [3, 1, 2], "B": [1, 2, 3]})
3654+
>>> df
3655+
A B
3656+
0 3 1
3657+
1 1 2
3658+
2 2 3
3659+
<BLANKLINE>
3660+
[3 rows x 2 columns]
3661+
3662+
Using a single function:
3663+
3664+
>>> df.agg('sum')
3665+
A 6.0
3666+
B 6.0
3667+
dtype: Float64
3668+
3669+
Using a list of functions:
3670+
3671+
>>> df.agg(['sum', 'mean'])
3672+
A B
3673+
sum 6.0 6.0
3674+
mean 2.0 2.0
3675+
<BLANKLINE>
3676+
[2 rows x 2 columns]
35943677
35953678
Args:
35963679
func (function):
@@ -3623,6 +3706,33 @@ def describe(self):
36233706
upper percentile is ``75``. The ``50`` percentile is the
36243707
same as the median.
36253708
3709+
**Examples:**
3710+
3711+
>>> import bigframes.pandas as bpd
3712+
>>> bpd.options.display.progress_bar = None
3713+
3714+
>>> df = bpd.DataFrame({"A": [3, 1, 2], "B": [0, 2, 8]})
3715+
>>> df
3716+
A B
3717+
0 3 0
3718+
1 1 2
3719+
2 2 8
3720+
<BLANKLINE>
3721+
[3 rows x 2 columns]
3722+
3723+
>>> df.describe()
3724+
A B
3725+
count 3.0 3.0
3726+
mean 2.0 3.333333
3727+
std 1.0 4.163332
3728+
min 1.0 0.0
3729+
25% 1.0 0.0
3730+
50% 2.0 2.0
3731+
75% 3.0 8.0
3732+
max 3.0 8.0
3733+
<BLANKLINE>
3734+
[8 rows x 2 columns]
3735+
36263736
Returns:
36273737
bigframes.dataframe.DataFrame: Summary statistics of the Series or Dataframe provided.
36283738
"""

0 commit comments

Comments
 (0)