diff --git a/third_party/bigframes_vendored/pandas/core/frame.py b/third_party/bigframes_vendored/pandas/core/frame.py index 00be9e5e9e..427e586c52 100644 --- a/third_party/bigframes_vendored/pandas/core/frame.py +++ b/third_party/bigframes_vendored/pandas/core/frame.py @@ -869,6 +869,97 @@ def drop( Remove columns by directly specifying column names. + **Examples:** + + >>> import bigframes.pandas as bpd + >>> bpd.options.display.progress_bar = None + + >>> df = bpd.DataFrame(np.arange(12).reshape(3, 4), + ... columns=['A', 'B', 'C', 'D']) + >>> df + A B C D + 0 0 1 2 3 + 1 4 5 6 7 + 2 8 9 10 11 + + [3 rows x 4 columns] + + Drop columns: + + >>> df.drop(['B', 'C'], axis=1) + A D + 0 0 3 + 1 4 7 + 2 8 11 + + [3 rows x 2 columns] + + >>> df.drop(columns=['B', 'C']) + A D + 0 0 3 + 1 4 7 + 2 8 11 + + [3 rows x 2 columns] + + Drop a row by index: + + >>> df.drop([0, 1]) + A B C D + 2 8 9 10 11 + + [1 rows x 4 columns] + + Drop columns and/or rows of MultiIndex DataFrame: + + >>> import pandas as pd + >>> midx = pd.MultiIndex(levels=[['llama', 'cow', 'falcon'], + ... ['speed', 'weight', 'length']], + ... codes=[[0, 0, 0, 1, 1, 1, 2, 2, 2], + ... [0, 1, 2, 0, 1, 2, 0, 1, 2]]) + >>> df = bpd.DataFrame(index=midx, columns=['big', 'small'], + ... data=[[45, 30], [200, 100], [1.5, 1], [30, 20], + ... [250, 150], [1.5, 0.8], [320, 250], + ... [1, 0.8], [0.3, 0.2]]) + >>> df + big small + llama speed 45.0 30.0 + weight 200.0 100.0 + length 1.5 1.0 + cow speed 30.0 20.0 + weight 250.0 150.0 + length 1.5 0.8 + falcon speed 320.0 250.0 + weight 1.0 0.8 + length 0.3 0.2 + + [9 rows x 2 columns] + + Drop a specific index and column combination from the MultiIndex + DataFrame, i.e., drop the index ``'cow'`` and column ``'small'``: + + >>> df.drop(index='cow', columns='small') + big + llama speed 45.0 + weight 200.0 + length 1.5 + falcon speed 320.0 + weight 1.0 + length 0.3 + + [6 rows x 1 columns] + + >>> df.drop(index='length', level=1) + big small + llama speed 45.0 30.0 + weight 200.0 100.0 + cow speed 30.0 20.0 + weight 250.0 150.0 + falcon speed 320.0 250.0 + weight 1.0 0.8 + + [6 rows x 2 columns] + Args: labels: Index or column labels to drop. @@ -4343,6 +4434,56 @@ def fillna(self, value): """ Fill NA/NaN values using the specified method. + **Examples:** + + >>> import bigframes.pandas as bpd + >>> bpd.options.display.progress_bar = None + + >>> df = bpd.DataFrame([[np.nan, 2, np.nan, 0], + ... [3, 4, np.nan, 1], + ... [np.nan, np.nan, np.nan, np.nan], + ... [np.nan, 3, np.nan, 4]], + ... columns=list("ABCD")).astype("Float64") + >>> df + A B C D + 0 2.0 0.0 + 1 3.0 4.0 1.0 + 2 + 3 3.0 4.0 + + [4 rows x 4 columns] + + Replace all NA elements with 0s. + + >>> df.fillna(0) + A B C D + 0 0.0 2.0 0.0 0.0 + 1 3.0 4.0 0.0 1.0 + 2 0.0 0.0 0.0 0.0 + 3 0.0 3.0 0.0 4.0 + + [4 rows x 4 columns] + + You can use fill values from another DataFrame: + + >>> df_fill = bpd.DataFrame(np.arange(12).reshape(3, 4), + ... columns=['A', 'B', 'C', 'D']) + >>> df_fill + A B C D + 0 0 1 2 3 + 1 4 5 6 7 + 2 8 9 10 11 + + [3 rows x 4 columns] + >>> df.fillna(df_fill) + A B C D + 0 0.0 2.0 2.0 0.0 + 1 3.0 4.0 6.0 1.0 + 2 8.0 9.0 10.0 11.0 + 3 3.0 4.0 + + [4 rows x 4 columns] + Args: value (scalar, Series): Value to use to fill holes (e.g. 0), alternately a diff --git a/third_party/bigframes_vendored/pandas/core/series.py b/third_party/bigframes_vendored/pandas/core/series.py index 366f32c77e..01cc3a0500 100644 --- a/third_party/bigframes_vendored/pandas/core/series.py +++ b/third_party/bigframes_vendored/pandas/core/series.py @@ -1062,6 +1062,55 @@ def drop( When using a multi-index, labels on different levels can be removed by specifying the level. + **Examples:** + + >>> import bigframes.pandas as bpd + >>> bpd.options.display.progress_bar = None + + >>> s = bpd.Series(data=np.arange(3), index=['A', 'B', 'C']) + >>> s + A 0 + B 1 + C 2 + dtype: Int64 + + Drop labels B and C: + + >>> s.drop(labels=['B', 'C']) + A 0 + dtype: Int64 + + Drop 2nd level label in MultiIndex Series: + + >>> import pandas as pd + >>> midx = pd.MultiIndex(levels=[['llama', 'cow', 'falcon'], + ... ['speed', 'weight', 'length']], + ... codes=[[0, 0, 0, 1, 1, 1, 2, 2, 2], + ... [0, 1, 2, 0, 1, 2, 0, 1, 2]]) + + >>> s = bpd.Series([45, 200, 1.2, 30, 250, 1.5, 320, 1, 0.3], + ... index=midx) + >>> s + llama speed 45.0 + weight 200.0 + length 1.2 + cow speed 30.0 + weight 250.0 + length 1.5 + falcon speed 320.0 + weight 1.0 + length 0.3 + dtype: Float64 + + >>> s.drop(labels='weight', level=1) + llama speed 45.0 + length 1.2 + cow speed 30.0 + length 1.5 + falcon speed 320.0 + length 0.3 + dtype: Float64 + Args: labels (single label or list-like): Index labels to drop. @@ -1193,6 +1242,38 @@ def fillna( """ Fill NA/NaN values using the specified method. + **Examples:** + + >>> import bigframes.pandas as bpd + >>> bpd.options.display.progress_bar = None + + >>> s = bpd.Series([np.nan, 2, np.nan, -1]) + >>> s + 0 + 1 2.0 + 2 + 3 -1.0 + dtype: Float64 + + Replace all NA elements with 0s. + + >>> s.fillna(0) + 0 0.0 + 1 2.0 + 2 0.0 + 3 -1.0 + dtype: Float64 + + You can use fill values from another Series: + + >>> s_fill = bpd.Series([11, 22, 33]) + >>> s.fillna(s_fill) + 0 11.0 + 1 2.0 + 2 33.0 + 3 -1.0 + dtype: Float64 + Args: value (scalar, dict, Series, or DataFrame, default None): Value to use to fill holes (e.g. 0).