From 5387d9577476c18b5ceb9bf964e2a56f9e1b00e3 Mon Sep 17 00:00:00 2001 From: stijnvanhoey Date: Wed, 7 Mar 2018 15:04:02 +0100 Subject: [PATCH 1/8] Shift text to short summary --- pandas/core/indexes/base.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/pandas/core/indexes/base.py b/pandas/core/indexes/base.py index d3a8f11a38715..01e87202a960d 100644 --- a/pandas/core/indexes/base.py +++ b/pandas/core/indexes/base.py @@ -1110,8 +1110,7 @@ def to_series(self, index=None, name=None): return Series(self._to_embed(), index=index, name=name) def to_frame(self, index=True): - """ - Create a DataFrame with a column containing the Index. + """Create a DataFrame with a column containing the Index. .. versionadded:: 0.21.0 From b99e4a20ccc824bfdfd3d55176bdf2641d6d5390 Mon Sep 17 00:00:00 2001 From: stijnvanhoey Date: Wed, 7 Mar 2018 15:06:07 +0100 Subject: [PATCH 2/8] Move default to parameter description --- pandas/core/indexes/base.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/pandas/core/indexes/base.py b/pandas/core/indexes/base.py index 01e87202a960d..c42535e9ca0bc 100644 --- a/pandas/core/indexes/base.py +++ b/pandas/core/indexes/base.py @@ -1116,8 +1116,9 @@ def to_frame(self, index=True): Parameters ---------- - index : boolean, default True - Set the index of the returned DataFrame as the original Index. + index : boolean + Set the index of the returned DataFrame as the original Index + (default True). Returns ------- From 90eb4affdae2a0cb229f7d92f9c737ea2c0f86aa Mon Sep 17 00:00:00 2001 From: stijnvanhoey Date: Wed, 7 Mar 2018 15:10:24 +0100 Subject: [PATCH 3/8] Split return info to separate line --- pandas/core/indexes/base.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/pandas/core/indexes/base.py b/pandas/core/indexes/base.py index c42535e9ca0bc..4c69c930c0103 100644 --- a/pandas/core/indexes/base.py +++ b/pandas/core/indexes/base.py @@ -1122,7 +1122,8 @@ def to_frame(self, index=True): Returns ------- - DataFrame : a DataFrame containing the original Index data. + DataFrame + DataFrame containing the original Index data. """ from pandas import DataFrame From 2e26d8af4c07c888814e92ea919d578c208bf253 Mon Sep 17 00:00:00 2001 From: stijnvanhoey Date: Wed, 7 Mar 2018 15:30:37 +0100 Subject: [PATCH 4/8] Provide example solutions --- pandas/core/indexes/base.py | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/pandas/core/indexes/base.py b/pandas/core/indexes/base.py index 4c69c930c0103..929af497259f5 100644 --- a/pandas/core/indexes/base.py +++ b/pandas/core/indexes/base.py @@ -1124,6 +1124,23 @@ def to_frame(self, index=True): ------- DataFrame DataFrame containing the original Index data. + + Examples + -------- + >>> idx = pd.Index(['Ant', 'Bear', 'Cow']) + >>> idx.to_frame() + 0 + Ant Ant + Bear Bear + Cow Cow + + By default, the original Index is reused. To enforce a new Index: + + >>> idx.to_frame(index=False) + 0 + 0 Ant + 1 Bear + 2 Cow """ from pandas import DataFrame From f3e10190be122686610bb7635f0ab69459883b60 Mon Sep 17 00:00:00 2001 From: Stijn Van Hoey Date: Wed, 7 Mar 2018 15:50:59 +0100 Subject: [PATCH 5/8] Remove trailing whitespace --- pandas/core/indexes/base.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pandas/core/indexes/base.py b/pandas/core/indexes/base.py index 929af497259f5..82c4f3792e450 100644 --- a/pandas/core/indexes/base.py +++ b/pandas/core/indexes/base.py @@ -1117,7 +1117,7 @@ def to_frame(self, index=True): Parameters ---------- index : boolean - Set the index of the returned DataFrame as the original Index + Set the index of the returned DataFrame as the original Index (default True). Returns From 535eba967c825fb1f42cb886fac8e029e372a3d7 Mon Sep 17 00:00:00 2001 From: Stijn Van Hoey Date: Wed, 7 Mar 2018 20:56:05 +0100 Subject: [PATCH 6/8] Move default to same line of type --- pandas/core/indexes/base.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/pandas/core/indexes/base.py b/pandas/core/indexes/base.py index 82c4f3792e450..fc740f52365e7 100644 --- a/pandas/core/indexes/base.py +++ b/pandas/core/indexes/base.py @@ -1116,9 +1116,8 @@ def to_frame(self, index=True): Parameters ---------- - index : boolean - Set the index of the returned DataFrame as the original Index - (default True). + index : boolean (default True) + Set the index of the returned DataFrame as the original Index. Returns ------- From e6cbbbe29dcc4ef365fca00fcbc244216d0b70b1 Mon Sep 17 00:00:00 2001 From: Joris Van den Bossche Date: Wed, 7 Mar 2018 21:12:02 +0100 Subject: [PATCH 7/8] update based on changes in guide --- pandas/core/indexes/base.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/pandas/core/indexes/base.py b/pandas/core/indexes/base.py index fc740f52365e7..b747aba12a4ac 100644 --- a/pandas/core/indexes/base.py +++ b/pandas/core/indexes/base.py @@ -1110,13 +1110,14 @@ def to_series(self, index=None, name=None): return Series(self._to_embed(), index=index, name=name) def to_frame(self, index=True): - """Create a DataFrame with a column containing the Index. + """ + Create a DataFrame with a column containing the Index. .. versionadded:: 0.21.0 Parameters ---------- - index : boolean (default True) + index : boolean, default True Set the index of the returned DataFrame as the original Index. Returns From b32b4165e4c988ea67370ed1e03cdd10e758c6e2 Mon Sep 17 00:00:00 2001 From: stijnvanhoey Date: Wed, 7 Mar 2018 22:10:58 +0100 Subject: [PATCH 8/8] Provide name to index initiation --- pandas/core/indexes/base.py | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/pandas/core/indexes/base.py b/pandas/core/indexes/base.py index b747aba12a4ac..b96bb22199fa1 100644 --- a/pandas/core/indexes/base.py +++ b/pandas/core/indexes/base.py @@ -1127,17 +1127,18 @@ def to_frame(self, index=True): Examples -------- - >>> idx = pd.Index(['Ant', 'Bear', 'Cow']) + >>> idx = pd.Index(['Ant', 'Bear', 'Cow'], name='animal') >>> idx.to_frame() - 0 - Ant Ant - Bear Bear - Cow Cow + animal + animal + Ant Ant + Bear Bear + Cow Cow By default, the original Index is reused. To enforce a new Index: >>> idx.to_frame(index=False) - 0 + animal 0 Ant 1 Bear 2 Cow