Skip to content

Commit cc7abd9

Browse files
DOC: clean old whatsnew files for 0.21.0 (#17999)
1 parent e38bd74 commit cc7abd9

File tree

4 files changed

+129
-37
lines changed

4 files changed

+129
-37
lines changed

doc/source/whatsnew/v0.12.0.txt

+3-3
Original file line numberDiff line numberDiff line change
@@ -236,10 +236,10 @@ I/O Enhancements
236236
.. ipython:: python
237237

238238
from pandas.util.testing import makeCustomDataframe as mkdf
239-
df = mkdf(5,3,r_idx_nlevels=2,c_idx_nlevels=4)
240-
df.to_csv('mi.csv',tupleize_cols=False)
239+
df = mkdf(5, 3, r_idx_nlevels=2, c_idx_nlevels=4)
240+
df.to_csv('mi.csv')
241241
print(open('mi.csv').read())
242-
pd.read_csv('mi.csv',header=[0,1,2,3],index_col=[0,1],tupleize_cols=False)
242+
pd.read_csv('mi.csv', header=[0,1,2,3], index_col=[0,1])
243243

244244
.. ipython:: python
245245
:suppress:

doc/source/whatsnew/v0.16.0.txt

+23-6
Original file line numberDiff line numberDiff line change
@@ -380,12 +380,29 @@ New Behavior
380380

381381
For ease of creation of series of categorical data, we have added the ability to pass keywords when calling ``.astype()``. These are passed directly to the constructor.
382382

383-
.. ipython:: python
384-
385-
s = Series(["a","b","c","a"]).astype('category',ordered=True)
386-
s
387-
s = Series(["a","b","c","a"]).astype('category',categories=list('abcdef'),ordered=False)
388-
s
383+
.. code-block:: python
384+
385+
In [54]: s = Series(["a","b","c","a"]).astype('category',ordered=True)
386+
387+
In [55]: s
388+
Out[55]:
389+
0 a
390+
1 b
391+
2 c
392+
3 a
393+
dtype: category
394+
Categories (3, object): [a < b < c]
395+
396+
In [56]: s = Series(["a","b","c","a"]).astype('category',categories=list('abcdef'),ordered=False)
397+
398+
In [57]: s
399+
Out[57]:
400+
0 a
401+
1 b
402+
2 c
403+
3 a
404+
dtype: category
405+
Categories (6, object): [a, b, c, d, e, f]
389406

390407

391408
.. _whatsnew_0160.api_breaking.other:

doc/source/whatsnew/v0.16.1.txt

+90-25
Original file line numberDiff line numberDiff line change
@@ -41,61 +41,126 @@ indexing with duplicates. This is a container around a ``Categorical`` (introduc
4141
and allows efficient indexing and storage of an index with a large number of duplicated elements. Prior to 0.16.1,
4242
setting the index of a ``DataFrame/Series`` with a ``category`` dtype would convert this to regular object-based ``Index``.
4343

44-
.. ipython :: python
44+
.. code-block:: ipython
45+
46+
In [1]: df = DataFrame({'A' : np.arange(6),
47+
...: 'B' : Series(list('aabbca')).astype('category',
48+
...: categories=list('cab'))
49+
...: })
50+
...:
51+
52+
In [2]: df
53+
Out[2]:
54+
A B
55+
0 0 a
56+
1 1 a
57+
2 2 b
58+
3 3 b
59+
4 4 c
60+
5 5 a
61+
62+
In [3]: df.dtypes
63+
Out[3]:
64+
A int64
65+
B category
66+
dtype: object
67+
68+
In [4]: df.B.cat.categories
69+
Out[4]: Index(['c', 'a', 'b'], dtype='object')
4570

46-
df = DataFrame({'A' : np.arange(6),
47-
'B' : Series(list('aabbca')).astype('category',
48-
categories=list('cab'))
49-
})
50-
df
51-
df.dtypes
52-
df.B.cat.categories
5371

5472
setting the index, will create create a ``CategoricalIndex``
5573

56-
.. ipython :: python
74+
.. code-block:: ipython
75+
76+
In [5]: df2 = df.set_index('B')
5777

58-
df2 = df.set_index('B')
59-
df2.index
78+
In [6]: df2.index
79+
Out[6]: CategoricalIndex(['a', 'a', 'b', 'b', 'c', 'a'], categories=['c', 'a', 'b'], ordered=False, name='B', dtype='category')
6080

6181
indexing with ``__getitem__/.iloc/.loc/.ix`` works similarly to an Index with duplicates.
6282
The indexers MUST be in the category or the operation will raise.
6383

64-
.. ipython :: python
84+
.. code-block:: ipython
6585

66-
df2.loc['a']
86+
In [7]: df2.loc['a']
87+
Out[7]:
88+
A
89+
B
90+
a 0
91+
a 1
92+
a 5
6793

6894
and preserves the ``CategoricalIndex``
6995

70-
.. ipython :: python
96+
.. code-block:: ipython
97+
98+
In [8]: df2.loc['a'].index
99+
Out[8]: CategoricalIndex(['a', 'a', 'a'], categories=['c', 'a', 'b'], ordered=False, name='B', dtype='category')
71100

72-
df2.loc['a'].index
73101

74102
sorting will order by the order of the categories
75103

76-
.. ipython :: python
104+
.. code-block:: ipython
77105

78-
df2.sort_index()
106+
In [9]: df2.sort_index()
107+
Out[9]:
108+
A
109+
B
110+
c 4
111+
a 0
112+
a 1
113+
a 5
114+
b 2
115+
b 3
79116

80117
groupby operations on the index will preserve the index nature as well
81118

82-
.. ipython :: python
119+
.. code-block:: ipython
120+
121+
In [10]: df2.groupby(level=0).sum()
122+
Out[10]:
123+
A
124+
B
125+
c 4
126+
a 6
127+
b 5
128+
129+
In [11]: df2.groupby(level=0).sum().index
130+
Out[11]: CategoricalIndex(['c', 'a', 'b'], categories=['c', 'a', 'b'], ordered=False, name='B', dtype='category')
83131

84-
df2.groupby(level=0).sum()
85-
df2.groupby(level=0).sum().index
86132

87133
reindexing operations, will return a resulting index based on the type of the passed
88134
indexer, meaning that passing a list will return a plain-old-``Index``; indexing with
89135
a ``Categorical`` will return a ``CategoricalIndex``, indexed according to the categories
90136
of the PASSED ``Categorical`` dtype. This allows one to arbitrarly index these even with
91137
values NOT in the categories, similarly to how you can reindex ANY pandas index.
92138

93-
.. ipython :: python
139+
.. code-block:: ipython
94140

95-
df2.reindex(['a','e'])
96-
df2.reindex(['a','e']).index
97-
df2.reindex(pd.Categorical(['a','e'],categories=list('abcde')))
98-
df2.reindex(pd.Categorical(['a','e'],categories=list('abcde'))).index
141+
In [12]: df2.reindex(['a','e'])
142+
Out[12]:
143+
A
144+
B
145+
a 0.0
146+
a 1.0
147+
a 5.0
148+
e NaN
149+
150+
In [13]: df2.reindex(['a','e']).index
151+
Out[13]: Index(['a', 'a', 'a', 'e'], dtype='object', name='B')
152+
153+
In [14]: df2.reindex(pd.Categorical(['a','e'],categories=list('abcde')))
154+
Out[14]:
155+
A
156+
B
157+
a 0.0
158+
a 1.0
159+
a 5.0
160+
e NaN
161+
162+
In [15]: df2.reindex(pd.Categorical(['a','e'],categories=list('abcde'))).index
163+
Out[15]: CategoricalIndex(['a', 'a', 'a', 'e'], categories=['a', 'b', 'c', 'd', 'e'], ordered=False, name='B', dtype='category')
99164

100165
See the :ref:`documentation <indexing.categoricalindex>` for more. (:issue:`7629`, :issue:`10038`, :issue:`10039`)
101166

doc/source/whatsnew/v0.18.1.txt

+13-3
Original file line numberDiff line numberDiff line change
@@ -440,13 +440,23 @@ Previous behavior:
440440

441441
New Behavior:
442442

443-
.. ipython:: python
443+
.. code-block:: python
444444

445445
# Output is a Series
446-
df.groupby(pd.TimeGrouper(key='date', freq='M')).apply(lambda x: x.value.sum())
446+
In [55]: df.groupby(pd.TimeGrouper(key='date', freq='M')).apply(lambda x: x.value.sum())
447+
Out[55]:
448+
date
449+
2000-10-31 10
450+
2000-11-30 13
451+
Freq: M, dtype: int64
447452

448453
# Output is a DataFrame
449-
df.groupby(pd.TimeGrouper(key='date', freq='M')).apply(lambda x: x[['value']].sum())
454+
In [56]: df.groupby(pd.TimeGrouper(key='date', freq='M')).apply(lambda x: x[['value']].sum())
455+
Out[56]:
456+
value
457+
date
458+
2000-10-31 10
459+
2000-11-30 13
450460

451461
.. _whatsnew_0181.read_csv_exceptions:
452462

0 commit comments

Comments
 (0)