From 9fc775a66c9d1b159aa23323875304ce33c30e8d Mon Sep 17 00:00:00 2001 From: BeanNan Date: Mon, 11 Jan 2021 23:44:17 +0800 Subject: [PATCH 1/4] DOC: NDFrame fillna method add use case --- pandas/core/generic.py | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/pandas/core/generic.py b/pandas/core/generic.py index 2f4340c17c5a7..55040e17b2636 100644 --- a/pandas/core/generic.py +++ b/pandas/core/generic.py @@ -148,7 +148,6 @@ you to specify a location to update with some value.""", } - bool_t = bool # Need alias because NDFrame has def bool: @@ -1632,7 +1631,6 @@ def _check_label_or_level_ambiguity(self, key, axis: int = 0) -> None: and key in self.axes[axis].names and any(key in self.axes[ax] for ax in other_axes) ): - # Build an informative and grammatical warning level_article, level_type = ( ("an", "index") if axis == 0 else ("a", "column") @@ -6317,7 +6315,7 @@ def fillna( ... [3, 4, np.nan, 1], ... [np.nan, np.nan, np.nan, 5], ... [np.nan, 3, np.nan, 4]], - ... columns=list('ABCD')) + ... columns=list("ABCD")) >>> df A B C D 0 NaN 2.0 NaN 0 @@ -6336,7 +6334,7 @@ def fillna( We can also propagate non-null values forward or backward. - >>> df.fillna(method='ffill') + >>> df.fillna(method="ffill") A B C D 0 NaN 2.0 NaN 0 1 3.0 4.0 NaN 1 @@ -6346,7 +6344,7 @@ def fillna( Replace all NaN elements in column 'A', 'B', 'C', and 'D', with 0, 1, 2, and 3 respectively. - >>> values = {{'A': 0, 'B': 1, 'C': 2, 'D': 3}} + >>> values = {{"A": 0, "B": 1, "C": 2, "D": 3}} >>> df.fillna(value=values) A B C D 0 0.0 2.0 2.0 0 @@ -6362,6 +6360,16 @@ def fillna( 1 3.0 4.0 NaN 1 2 NaN 1.0 NaN 5 3 NaN 3.0 NaN 4 + + Replace with a DataFrame with the same column name + + >>> df2 = pd.DataFrame(np.zeros((4, 4)), columns=list("ABCD")) + >>> df.fillna(df2) + A B C D + 0 0.0 2.0 0.0 0 + 1 3.0 4.0 0.0 1 + 2 0.0 0.0 0.0 5 + 3 0.0 3.0 0.0 4 """ inplace = validate_bool_kwarg(inplace, "inplace") value, method = validate_fillna_kwargs(value, method) From a5fc4566c7905abadc83dbf89cde1ba51ac16e4a Mon Sep 17 00:00:00 2001 From: BeanNan Date: Wed, 13 Jan 2021 21:44:05 +0800 Subject: [PATCH 2/4] DOC: fix use case --- pandas/core/generic.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/pandas/core/generic.py b/pandas/core/generic.py index 55040e17b2636..d56e6957cb698 100644 --- a/pandas/core/generic.py +++ b/pandas/core/generic.py @@ -148,6 +148,7 @@ you to specify a location to update with some value.""", } + bool_t = bool # Need alias because NDFrame has def bool: @@ -1631,6 +1632,7 @@ def _check_label_or_level_ambiguity(self, key, axis: int = 0) -> None: and key in self.axes[axis].names and any(key in self.axes[ax] for ax in other_axes) ): + # Build an informative and grammatical warning level_article, level_type = ( ("an", "index") if axis == 0 else ("a", "column") @@ -6361,9 +6363,9 @@ def fillna( 2 NaN 1.0 NaN 5 3 NaN 3.0 NaN 4 - Replace with a DataFrame with the same column name + Replacement happens along same column names and same indices - >>> df2 = pd.DataFrame(np.zeros((4, 4)), columns=list("ABCD")) + >>> df2 = pd.DataFrame(np.zeros((5, 5)), columns=list("ABCED")) >>> df.fillna(df2) A B C D 0 0.0 2.0 0.0 0 From 6fea6eee28e1ad17596e5c8798f578afc4f19adb Mon Sep 17 00:00:00 2001 From: BeanNan Date: Thu, 21 Jan 2021 22:53:01 +0800 Subject: [PATCH 3/4] DOC: update tip --- pandas/core/generic.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/pandas/core/generic.py b/pandas/core/generic.py index d56e6957cb698..4ea3129ed978c 100644 --- a/pandas/core/generic.py +++ b/pandas/core/generic.py @@ -6363,7 +6363,8 @@ def fillna( 2 NaN 1.0 NaN 5 3 NaN 3.0 NaN 4 - Replacement happens along same column names and same indices + When filling using a DataFrame, replacement happens along + the same column names and same indices >>> df2 = pd.DataFrame(np.zeros((5, 5)), columns=list("ABCED")) >>> df.fillna(df2) From 2cbc5e3ea01d83346d5dd414dea5cc09ba98d567 Mon Sep 17 00:00:00 2001 From: BeanNan Date: Sun, 24 Jan 2021 21:57:49 +0800 Subject: [PATCH 4/4] update case --- pandas/core/generic.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pandas/core/generic.py b/pandas/core/generic.py index 4ea3129ed978c..e34cdf1482021 100644 --- a/pandas/core/generic.py +++ b/pandas/core/generic.py @@ -6366,7 +6366,7 @@ def fillna( When filling using a DataFrame, replacement happens along the same column names and same indices - >>> df2 = pd.DataFrame(np.zeros((5, 5)), columns=list("ABCED")) + >>> df2 = pd.DataFrame(np.zeros((4, 4)), columns=list("ABCE")) >>> df.fillna(df2) A B C D 0 0.0 2.0 0.0 0