From 8bce6750d927a0f8a3ee533603f7434cf12f765b Mon Sep 17 00:00:00 2001 From: lastone9182 Date: Sat, 10 Mar 2018 14:59:13 +0900 Subject: [PATCH 1/6] DOC: Improved the docstring of dtypes/ftypes property in NDFrame --- pandas/core/generic.py | 49 +++++++++++++++++++++++++++++++++++++++++- 1 file changed, 48 insertions(+), 1 deletion(-) diff --git a/pandas/core/generic.py b/pandas/core/generic.py index a893b2ba1a189..fa45b08aac2d4 100644 --- a/pandas/core/generic.py +++ b/pandas/core/generic.py @@ -4275,7 +4275,29 @@ def get_ftype_counts(self): @property def dtypes(self): - """Return the dtypes in this object.""" + """ + Return the dtypes in this object. + + Notes + ----- + It returns a Series with the data type of each column. + If object contains data multiple dtypes in a single column, + dtypes will be chosen to accommodate all of the data types. + ``object`` is the most general. + + Examples + -------- + >>> df = pd.DataFrame({'f': pd.np.random.rand(3), + ... 'i': 1, + ... 'd': pd.Timestamp('20180310'), + ... 'o': 'foo'}) + >>> df.dtypes + f float64 + i int64 + d datetime64[ns] + o object + dtype: object + """ from pandas import Series return Series(self._data.get_dtypes(), index=self._info_axis, dtype=np.object_) @@ -4285,6 +4307,31 @@ def ftypes(self): """ Return the ftypes (indication of sparse/dense and dtype) in this object. + + Notes + ----- + Sparse data should have the same dtypes as its dense representation + + See Also + -------- + dtypes, SparseDataFrame + + Examples + -------- + >>> arr = pd.np.random.randn(100, 4) + >>> arr[arr < .8] = pd.np.nan + >>> pd.DataFrame(arr).ftypes + 0 float64:dense + 1 float64:dense + 2 float64:dense + 3 float64:dense + dtype: object + >>> pd.SparseDataFrame(arr).ftypes + 0 float64:sparse + 1 float64:sparse + 2 float64:sparse + 3 float64:sparse + dtype: object """ from pandas import Series return Series(self._data.get_ftypes(), index=self._info_axis, From 05306dbc61234e923e24734db7b9e9eddf8a064d Mon Sep 17 00:00:00 2001 From: lastone9182 Date: Sun, 11 Mar 2018 16:36:33 +0900 Subject: [PATCH 2/6] DOC: Improved the docstring of dtypes/ftypes --- pandas/core/generic.py | 47 ++++++++++++++++++++++++++++++------------ 1 file changed, 34 insertions(+), 13 deletions(-) diff --git a/pandas/core/generic.py b/pandas/core/generic.py index fa45b08aac2d4..2c8c7efc62a3d 100644 --- a/pandas/core/generic.py +++ b/pandas/core/generic.py @@ -4278,17 +4278,25 @@ def dtypes(self): """ Return the dtypes in this object. - Notes - ----- - It returns a Series with the data type of each column. + This returns a Series with the data type of each column. + The result's index is original DataFrame's columns. If object contains data multiple dtypes in a single column, dtypes will be chosen to accommodate all of the data types. ``object`` is the most general. + Returns + ------- + pandas.Series + The data type of each column. + + See Also + -------- + pandas.DataFrame.ftypes + Examples -------- - >>> df = pd.DataFrame({'f': pd.np.random.rand(3), - ... 'i': 1, + >>> df = pd.DataFrame({'f': [1.0], + ... 'i': [1], ... 'd': pd.Timestamp('20180310'), ... 'o': 'foo'}) >>> df.dtypes @@ -4305,21 +4313,34 @@ def dtypes(self): @property def ftypes(self): """ - Return the ftypes (indication of sparse/dense and dtype) - in this object. + Return the ftypes (indication of sparse/dense and dtype) in this object. - Notes - ----- - Sparse data should have the same dtypes as its dense representation + This returns a Series with the data type of each column. + The result's index is original DataFrame's columns. + If object contains data multiple dtypes in a single column, + dtypes will be chosen to accommodate all of the data types. + ``object`` is the most general. + All of the standard pandas data structures have a to_sparse method. + The result's tracks where data has been "sparsified". + + Returns + ------- + pandas.Series + The data type and indication of sparse/dense of each column. See Also -------- - dtypes, SparseDataFrame + pandas.DataFrame.dtypes, pandas.SparseDataFrame + + Notes + ----- + Sparse data should have the same dtypes as its dense representation. Examples -------- - >>> arr = pd.np.random.randn(100, 4) - >>> arr[arr < .8] = pd.np.nan + >>> import numpy as np + >>> arr = np.random.RandomState(0).randn(100, 4) + >>> arr[arr < .8] = np.nan >>> pd.DataFrame(arr).ftypes 0 float64:dense 1 float64:dense From 1b34fcdaf0e29756993a0a2ab3f6c9692d173b7d Mon Sep 17 00:00:00 2001 From: lastone9182 Date: Sun, 11 Mar 2018 16:47:19 +0900 Subject: [PATCH 3/6] DOC: Improved the docstring of dtypes/ftypes --- pandas/core/generic.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pandas/core/generic.py b/pandas/core/generic.py index 2c8c7efc62a3d..8800aa3e1d0da 100644 --- a/pandas/core/generic.py +++ b/pandas/core/generic.py @@ -4276,7 +4276,7 @@ def get_ftype_counts(self): @property def dtypes(self): """ - Return the dtypes in this object. + Return the dtypes in DataFrame. This returns a Series with the data type of each column. The result's index is original DataFrame's columns. @@ -4313,7 +4313,7 @@ def dtypes(self): @property def ftypes(self): """ - Return the ftypes (indication of sparse/dense and dtype) in this object. + Return the ftypes (indication of sparse/dense and dtype) in DataFrame. This returns a Series with the data type of each column. The result's index is original DataFrame's columns. From 14cc494a403b2be8df921f906ac065716d7e9bc0 Mon Sep 17 00:00:00 2001 From: Tom Augspurger Date: Sun, 11 Mar 2018 07:09:02 -0500 Subject: [PATCH 4/6] Grammar, updates --- pandas/core/generic.py | 26 +++++++++++--------------- 1 file changed, 11 insertions(+), 15 deletions(-) diff --git a/pandas/core/generic.py b/pandas/core/generic.py index 8800aa3e1d0da..bbb2c7ddd4074 100644 --- a/pandas/core/generic.py +++ b/pandas/core/generic.py @@ -4276,13 +4276,11 @@ def get_ftype_counts(self): @property def dtypes(self): """ - Return the dtypes in DataFrame. + Return the dtypes in the DataFrame. This returns a Series with the data type of each column. - The result's index is original DataFrame's columns. - If object contains data multiple dtypes in a single column, - dtypes will be chosen to accommodate all of the data types. - ``object`` is the most general. + The result's index is the original DataFrame's columns. Columns + with mixed types are stored in with the ``object`` dtype. Returns ------- @@ -4291,14 +4289,14 @@ def dtypes(self): See Also -------- - pandas.DataFrame.ftypes + pandas.DataFrame.ftypes : dtype and sparsity information. Examples -------- >>> df = pd.DataFrame({'f': [1.0], ... 'i': [1], - ... 'd': pd.Timestamp('20180310'), - ... 'o': 'foo'}) + ... 'd': [pd.Timestamp('20180310')], + ... 'o': ['foo']}) >>> df.dtypes f float64 i int64 @@ -4316,12 +4314,8 @@ def ftypes(self): Return the ftypes (indication of sparse/dense and dtype) in DataFrame. This returns a Series with the data type of each column. - The result's index is original DataFrame's columns. - If object contains data multiple dtypes in a single column, - dtypes will be chosen to accommodate all of the data types. - ``object`` is the most general. - All of the standard pandas data structures have a to_sparse method. - The result's tracks where data has been "sparsified". + The result's index is the original DataFrame's columns. Columns + with mixed types are stored in with the ``object`` dtype. Returns ------- @@ -4330,7 +4324,8 @@ def ftypes(self): See Also -------- - pandas.DataFrame.dtypes, pandas.SparseDataFrame + pandas.DataFrame.dtypes: Series with just dtype information. + pandas.SparseDataFrame : Container for sparse tabular data. Notes ----- @@ -4347,6 +4342,7 @@ def ftypes(self): 2 float64:dense 3 float64:dense dtype: object + >>> pd.SparseDataFrame(arr).ftypes 0 float64:sparse 1 float64:sparse From 14b754f887eb6839be0c9f133549578e79ecad8b Mon Sep 17 00:00:00 2001 From: Joris Van den Bossche Date: Sun, 11 Mar 2018 13:23:16 +0100 Subject: [PATCH 5/6] use longer column names --- pandas/core/generic.py | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/pandas/core/generic.py b/pandas/core/generic.py index bbb2c7ddd4074..637089396a761 100644 --- a/pandas/core/generic.py +++ b/pandas/core/generic.py @@ -4293,15 +4293,15 @@ def dtypes(self): Examples -------- - >>> df = pd.DataFrame({'f': [1.0], - ... 'i': [1], - ... 'd': [pd.Timestamp('20180310')], - ... 'o': ['foo']}) + >>> df = pd.DataFrame({'float': [1.0], + ... 'int': [1], + ... 'datetime': [pd.Timestamp('20180310')], + ... 'string': ['foo']}) >>> df.dtypes - f float64 - i int64 - d datetime64[ns] - o object + float float64 + int int64 + datetime datetime64[ns] + string object dtype: object """ from pandas import Series From 80589312ef7c47696af2fe628c36c4c60fcb4765 Mon Sep 17 00:00:00 2001 From: Tom Augspurger Date: Mon, 12 Mar 2018 16:10:44 -0500 Subject: [PATCH 6/6] Updates --- 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 637089396a761..8fedaabca84a8 100644 --- a/pandas/core/generic.py +++ b/pandas/core/generic.py @@ -4280,7 +4280,8 @@ def dtypes(self): This returns a Series with the data type of each column. The result's index is the original DataFrame's columns. Columns - with mixed types are stored in with the ``object`` dtype. + with mixed types are stored with the ``object`` dtype. See + :ref:`the User Guide ` for more. Returns ------- @@ -4315,7 +4316,8 @@ def ftypes(self): This returns a Series with the data type of each column. The result's index is the original DataFrame's columns. Columns - with mixed types are stored in with the ``object`` dtype. + with mixed types are stored with the ``object`` dtype. See + :ref:`the User Guide ` for more. Returns -------