From 50a3042cc36542a6c27a3569cfd0bc967c529779 Mon Sep 17 00:00:00 2001 From: Jovixe Date: Sat, 10 Mar 2018 16:31:04 +0300 Subject: [PATCH 1/4] add DateTime.to_frame example to base.py --- pandas/core/indexes/base.py | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/pandas/core/indexes/base.py b/pandas/core/indexes/base.py index 7e6ae88a26e7c..fd4003b78181f 100644 --- a/pandas/core/indexes/base.py +++ b/pandas/core/indexes/base.py @@ -1168,6 +1168,28 @@ def to_frame(self, index=True): 0 Ant 1 Bear 2 Cow + + Application to datetimes + + >>> dt = ['04/27/2008 05:28 AM', '04/22/2008 07:19 AM', '10/09/2008 01:44 PM', '12/25/2008 09:50 AM', '08/19/2008 07:30 PM', '03/07/2008 11:04 PM', '12/22/2008 12:08 PM', '07/01/2008 05:36 AM', '09/06/2008 04:53 AM', '01/23/2008 07:43 PM'] + >>> con_dt = pd.to_datetime(dt) + >>> df = con_dt.to_frame(index=True) + >>> df[0] + 2008-04-27 05:28:00 2008-04-27 05:28:00 + 2008-04-22 07:19:00 2008-04-22 07:19:00 + 2008-10-09 13:44:00 2008-10-09 13:44:00 + 2008-12-25 09:50:00 2008-12-25 09:50:00 + 2008-08-19 19:30:00 2008-08-19 19:30:00 + 2008-03-07 23:04:00 2008-03-07 23:04:00 + 2008-12-22 12:08:00 2008-12-22 12:08:00 + 2008-07-01 05:36:00 2008-07-01 05:36:00 + 2008-09-06 04:53:00 2008-09-06 04:53:00 + 2008-01-23 19:43:00 2008-01-23 19:43:00 + Name: 0, dtype: datetime64[ns] + + See Also + -------- + pandas.Series.to_frame : Convert Series to DataFrame """ from pandas import DataFrame From 4830213788a037c32a6719360c44d643ece2ad9d Mon Sep 17 00:00:00 2001 From: Jovixe Date: Sat, 10 Mar 2018 16:53:12 +0300 Subject: [PATCH 2/4] edits to the example --- pandas/core/indexes/base.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/pandas/core/indexes/base.py b/pandas/core/indexes/base.py index fd4003b78181f..acdfd922f0a52 100644 --- a/pandas/core/indexes/base.py +++ b/pandas/core/indexes/base.py @@ -1171,7 +1171,11 @@ def to_frame(self, index=True): Application to datetimes - >>> dt = ['04/27/2008 05:28 AM', '04/22/2008 07:19 AM', '10/09/2008 01:44 PM', '12/25/2008 09:50 AM', '08/19/2008 07:30 PM', '03/07/2008 11:04 PM', '12/22/2008 12:08 PM', '07/01/2008 05:36 AM', '09/06/2008 04:53 AM', '01/23/2008 07:43 PM'] + >>> dt = ['04/27/2008 05:28 AM', '04/22/2008 07:19 AM', + ... '10/09/2008 01:44 PM', '12/25/2008 09:50 AM', + ... '08/19/2008 07:30 PM', '03/07/2008 11:04 PM', + ... '12/22/2008 12:08 PM', '07/01/2008 05:36 AM', + ... '09/06/2008 04:53 AM', '01/23/2008 07:43 PM'] >>> con_dt = pd.to_datetime(dt) >>> df = con_dt.to_frame(index=True) >>> df[0] From 2890ce1716c9c3e19bdde4849aca9c88c2345a7f Mon Sep 17 00:00:00 2001 From: Jovixe <33747872+ryananyangu@users.noreply.github.com> Date: Sat, 10 Mar 2018 19:54:14 +0300 Subject: [PATCH 3/4] PEP8 trailling white space removed --- 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 acdfd922f0a52..05afe815e2c3c 100644 --- a/pandas/core/indexes/base.py +++ b/pandas/core/indexes/base.py @@ -1174,7 +1174,7 @@ def to_frame(self, index=True): >>> dt = ['04/27/2008 05:28 AM', '04/22/2008 07:19 AM', ... '10/09/2008 01:44 PM', '12/25/2008 09:50 AM', ... '08/19/2008 07:30 PM', '03/07/2008 11:04 PM', - ... '12/22/2008 12:08 PM', '07/01/2008 05:36 AM', + ... '12/22/2008 12:08 PM', '07/01/2008 05:36 AM', ... '09/06/2008 04:53 AM', '01/23/2008 07:43 PM'] >>> con_dt = pd.to_datetime(dt) >>> df = con_dt.to_frame(index=True) From 366c3ead7b66be8249d8b1b73d26fa04fbe2fe83 Mon Sep 17 00:00:00 2001 From: Tom Augspurger Date: Fri, 16 Mar 2018 16:20:14 -0500 Subject: [PATCH 4/4] Updated [ci skip] [ci skip] --- pandas/core/indexes/base.py | 33 ++++++--------------------------- 1 file changed, 6 insertions(+), 27 deletions(-) diff --git a/pandas/core/indexes/base.py b/pandas/core/indexes/base.py index 05afe815e2c3c..2258fcc347aea 100644 --- a/pandas/core/indexes/base.py +++ b/pandas/core/indexes/base.py @@ -1151,12 +1151,17 @@ def to_frame(self, index=True): DataFrame DataFrame containing the original Index data. + See Also + -------- + Index.to_series : Convert an Index to a Series. + Series.to_frame : Convert Series to DataFrame. + Examples -------- >>> idx = pd.Index(['Ant', 'Bear', 'Cow'], name='animal') >>> idx.to_frame() animal - animal + animal Ant Ant Bear Bear Cow Cow @@ -1168,32 +1173,6 @@ def to_frame(self, index=True): 0 Ant 1 Bear 2 Cow - - Application to datetimes - - >>> dt = ['04/27/2008 05:28 AM', '04/22/2008 07:19 AM', - ... '10/09/2008 01:44 PM', '12/25/2008 09:50 AM', - ... '08/19/2008 07:30 PM', '03/07/2008 11:04 PM', - ... '12/22/2008 12:08 PM', '07/01/2008 05:36 AM', - ... '09/06/2008 04:53 AM', '01/23/2008 07:43 PM'] - >>> con_dt = pd.to_datetime(dt) - >>> df = con_dt.to_frame(index=True) - >>> df[0] - 2008-04-27 05:28:00 2008-04-27 05:28:00 - 2008-04-22 07:19:00 2008-04-22 07:19:00 - 2008-10-09 13:44:00 2008-10-09 13:44:00 - 2008-12-25 09:50:00 2008-12-25 09:50:00 - 2008-08-19 19:30:00 2008-08-19 19:30:00 - 2008-03-07 23:04:00 2008-03-07 23:04:00 - 2008-12-22 12:08:00 2008-12-22 12:08:00 - 2008-07-01 05:36:00 2008-07-01 05:36:00 - 2008-09-06 04:53:00 2008-09-06 04:53:00 - 2008-01-23 19:43:00 2008-01-23 19:43:00 - Name: 0, dtype: datetime64[ns] - - See Also - -------- - pandas.Series.to_frame : Convert Series to DataFrame """ from pandas import DataFrame