From f5554922ab237c03671adbe136b5a55e0b22f547 Mon Sep 17 00:00:00 2001 From: Kaiqi Dong Date: Sun, 9 Dec 2018 20:38:59 +0100 Subject: [PATCH 1/3] fix issue 24180 --- doc/source/reshaping.rst | 25 ++++++++++++++----------- setup.cfg | 3 +++ 2 files changed, 17 insertions(+), 11 deletions(-) diff --git a/doc/source/reshaping.rst b/doc/source/reshaping.rst index 059e6eb2138f3..d9fbb52f2e56a 100644 --- a/doc/source/reshaping.rst +++ b/doc/source/reshaping.rst @@ -18,12 +18,12 @@ Reshaping by pivoting DataFrame objects tm.N = 3 def unpivot(frame): - N, K = frame.shape - data = {'value': frame.to_numpy().ravel('F'), - 'variable': np.asarray(frame.columns).repeat(N), - 'date': np.tile(np.asarray(frame.index), K)} - columns = ['date', 'variable', 'value'] - return pd.DataFrame(data, columns=columns) + N, K = frame.shape + data = {'value': frame.to_numpy().ravel('F'), + 'variable': np.asarray(frame.columns).repeat(N), + 'date': np.tile(np.asarray(frame.index), K)} + columns = ['date', 'variable', 'value'] + return pd.DataFrame(data, columns=columns) df = unpivot(tm.makeTimeDataFrame()) @@ -371,8 +371,8 @@ Consider a data set like this: 'C': ['foo', 'foo', 'foo', 'bar', 'bar', 'bar'] * 4, 'D': np.random.randn(24), 'E': np.random.randn(24), - 'F': [datetime.datetime(2013, i, 1) for i in range(1, 13)] + - [datetime.datetime(2013, i, 15) for i in range(1, 13)]}) + 'F': [datetime.datetime(2013, i, 1) for i in range(1, 13)] + + [datetime.datetime(2013, i, 15) for i in range(1, 13)]}) df We can produce pivot tables from this data very easily: @@ -397,7 +397,8 @@ Also, you can use ``Grouper`` for ``index`` and ``columns`` keywords. For detail .. ipython:: python - pd.pivot_table(df, values='D', index=pd.Grouper(freq='M', key='F'), columns='C') + pd.pivot_table(df, values='D', index=pd.Grouper(freq='M', key='F'), + columns='C') You can render a nice output of the table omitting the missing values by calling ``to_string`` if you wish: @@ -693,6 +694,7 @@ handling of NaN: .. code-block:: ipython + In [1]: x = pd.Series(['A', 'A', np.nan, 'B', 3.14, np.inf]) In [2]: pd.factorize(x, sort=True) Out[2]: (array([ 2, 2, -1, 3, 0, 1]), @@ -721,7 +723,8 @@ DataFrame will be pivoted in the answers below. n = 20 cols = np.array(['key', 'row', 'item', 'col']) - df = cols + pd.DataFrame((np.random.randint(5, size=(n, 4)) // [2, 1, 2, 1]).astype(str)) + df = cols + pd.DataFrame((np.random.randint(5, size=(n, 4)) + // [2, 1, 2, 1]).astype(str)) df.columns = cols df = df.join(pd.DataFrame(np.random.rand(n, 2).round(2)).add_prefix('val')) @@ -734,7 +737,7 @@ Suppose we wanted to pivot ``df`` such that the ``col`` values are columns, ``row`` values are the index, and the mean of ``val0`` are the values? In particular, the resulting DataFrame should look like: -.. code-block:: ipython +.. note:: col col0 col1 col2 col3 col4 row diff --git a/setup.cfg b/setup.cfg index 73a3a6c136b53..266fe9f9f5f5c 100644 --- a/setup.cfg +++ b/setup.cfg @@ -88,6 +88,9 @@ exclude = doc/source/options.rst doc/source/release.rst doc/source/reshaping.rst + doc/source/comparison_with_sas.rst + doc/source/comparison_with_sql.rst + doc/source/comparison_with_stata.rst doc/source/visualization.rst From c0e79491d56e82fc39e5fee641490131f80062cb Mon Sep 17 00:00:00 2001 From: Kaiqi Dong Date: Sun, 9 Dec 2018 22:00:11 +0100 Subject: [PATCH 2/3] remove reshaping.rst --- setup.cfg | 1 - 1 file changed, 1 deletion(-) diff --git a/setup.cfg b/setup.cfg index 266fe9f9f5f5c..2d38d23b3b194 100644 --- a/setup.cfg +++ b/setup.cfg @@ -87,7 +87,6 @@ exclude = doc/source/missing_data.rst doc/source/options.rst doc/source/release.rst - doc/source/reshaping.rst doc/source/comparison_with_sas.rst doc/source/comparison_with_sql.rst doc/source/comparison_with_stata.rst From 2c99c6e12489e452215d41e063592822a4b35865 Mon Sep 17 00:00:00 2001 From: Kaiqi Dong Date: Sun, 9 Dec 2018 22:09:06 +0100 Subject: [PATCH 3/3] remove rsts --- setup.cfg | 3 --- 1 file changed, 3 deletions(-) diff --git a/setup.cfg b/setup.cfg index 2d38d23b3b194..413b0a3ea3b8f 100644 --- a/setup.cfg +++ b/setup.cfg @@ -87,9 +87,6 @@ exclude = doc/source/missing_data.rst doc/source/options.rst doc/source/release.rst - doc/source/comparison_with_sas.rst - doc/source/comparison_with_sql.rst - doc/source/comparison_with_stata.rst doc/source/visualization.rst