Skip to content

Commit 8ec1c97

Browse files
committed
DOC: more miscellaneous docs about new 0.5 features
1 parent f838ff9 commit 8ec1c97

File tree

6 files changed

+92
-25
lines changed

6 files changed

+92
-25
lines changed

RELEASE.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,7 @@ Thanks
197197
- Daniel Fortunov
198198
- Aman Thakral
199199
- Luca Beltrame
200+
- Wouter Overmeire
200201

201202
pandas 0.4.3
202203
============

TODO.rst

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,13 +33,11 @@ TODO docs
3333
- DONE & and | for intersection / union
3434
- DONE Update to reflect Python 3 support in intro
3535
- DONE Index / MultiIndex names
36-
37-
- Unstack / stack by level name
38-
- name attribute on Series
36+
- DONE Unstack / stack by level name
37+
- DONE name attribute on Series
3938

4039
- Inner join on key
4140
- Multi-key joining
42-
4341
- align functions
4442
- df[col_list]
4543
- Panel.rename_axis

doc/source/dsintro.rst

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,20 @@ tools for working with labeled data.
181181
of course have the option of dropping labels with missing data via the
182182
**dropna** function.
183183

184+
Name attribute
185+
~~~~~~~~~~~~~~
186+
187+
Series can also have a ``name`` attribute:
188+
189+
.. ipython:: python
190+
191+
s = Series(np.random.randn(5), name='something')
192+
s
193+
s.name
194+
195+
The Series ``name`` will be assigned automatically in many cases, in particular
196+
when taking 1D slices of DataFrame as you will see below.
197+
184198
.. _basics.dataframe:
185199

186200
DataFrame

doc/source/indexing.rst

Lines changed: 59 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -302,6 +302,58 @@ values, though setting arbitrary vectors is not yet supported:
302302
df2.ix[3] = np.nan
303303
df2
304304
305+
.. _indexing.class:
306+
307+
Index objects
308+
-------------
309+
310+
The pandas Index class and its subclasses can be viewed as implementing an
311+
*ordered set* in addition to providing the support infrastructure necessary for
312+
lookups, data alignment, and reindexing. The easiest way to create one directly
313+
is to pass a list or other sequence to ``Index``:
314+
315+
.. ipython:: python
316+
317+
index = Index(['e', 'd', 'a', 'b'])
318+
index
319+
'd' in index
320+
321+
You can also pass a ``name`` to be stored in the index:
322+
323+
324+
.. ipython:: python
325+
326+
index = Index(['e', 'd', 'a', 'b'], name='something')
327+
index.name
328+
329+
Starting with pandas 0.5, the name, if set, will be shown in the console
330+
display:
331+
332+
.. ipython:: python
333+
334+
index = Index(range(5), name='rows')
335+
columns = Index(['A', 'B', 'C'], name='cols')
336+
df = DataFrame(np.random.randn(5, 3), index=index, columns=columns)
337+
df
338+
df['A']
339+
340+
341+
Set operations on Index objects
342+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
343+
344+
The three main operations are ``union (|)``, ``intersection (&)``, and ``diff
345+
(-)``. These can be directly called as instance methods or used via overloaded
346+
operators:
347+
348+
.. ipython:: python
349+
350+
a = Index(['c', 'b', 'a'])
351+
b = Index(['c', 'e', 'd'])
352+
a.union(b)
353+
a | b
354+
a & b
355+
a - b
356+
305357
.. _indexing.hierarchical:
306358

307359
Hierarchical indexing (MultiIndex)
@@ -558,14 +610,15 @@ attribute. These will get automatically assigned in various places where
558610
Some gory internal details
559611
~~~~~~~~~~~~~~~~~~~~~~~~~~
560612

561-
Internally, the ``MultiIndex`` consists of two things: the **levels** and the
562-
**labels**:
613+
Internally, the ``MultiIndex`` consists of a few things: the **levels**, the
614+
integer **labels**, and the level **names**:
563615

564616
.. ipython:: python
565617
566618
index
567619
index.levels
568620
index.labels
621+
index.names
569622
570623
You can probably guess that the labels determine which unique element is
571624
identified with that location at each layer of the index. It's important to
@@ -584,16 +637,6 @@ To do this, use the ``swaplevels`` function:
584637
df
585638
df.swaplevels(0, 1)
586639
587-
Index methods
588-
-------------
589-
590-
The pandas Index class and its subclasses can be viewed as implementing an
591-
*ordered set* in addition to providing the support infrastructure necessary for
592-
lookups, data alignment, and reindexing.
593-
594-
Set operations on Index objects
595-
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
596-
597640
Indexing internal details
598641
-------------------------
599642

@@ -603,13 +646,15 @@ Indexing internal details
603646
codebase. And the source code is still the best place to look at the
604647
specifics of how things are implemented.
605648

606-
In pandas there are 3 distinct objects which can serve as valid containers for
607-
the axis labels:
649+
In pandas there are a few objects implemented which can serve as valid
650+
containers for the axis labels:
608651

609652
- ``Index``: the generic "ordered set" object, an ndarray of object dtype
610653
assuming nothing about its contents. The labels must be hashable (and
611654
likely immutable) and unique. Populates a dict of label to location in
612655
Cython to do :math:`O(1)` lookups.
656+
- ``Int64Index``: a version of ``Index`` highly optimized for 64-bit integer
657+
data, such as time stamps
613658
- ``MultiIndex``: the standard hierarchical index object
614659
- ``DateRange``: fixed frequency date range generated from a time rule or
615660
DateOffset. An ndarray of Python datetime objects

doc/source/reshaping.rst

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,9 @@
1111
randn = np.random.randn
1212
np.set_printoptions(precision=4, suppress=True)
1313
14-
**********************
15-
Reshaping fundamentals
16-
**********************
14+
**************************
15+
Reshaping and Pivot Tables
16+
**************************
1717

1818
Reshaping by pivoting DataFrame objects
1919
---------------------------------------
@@ -113,7 +113,7 @@ take a prior example data set from the hierarchical indexing section:
113113
'foo', 'foo', 'qux', 'qux'],
114114
['one', 'two', 'one', 'two',
115115
'one', 'two', 'one', 'two']])
116-
index = MultiIndex.from_tuples(tuples)
116+
index = MultiIndex.from_tuples(tuples, names=['first', 'second'])
117117
df = DataFrame(randn(8, 2), index=index, columns=['A', 'B'])
118118
df2 = df[:4]
119119
df2
@@ -142,6 +142,13 @@ unstacks the **last level**:
142142
stacked.unstack(1)
143143
stacked.unstack(0)
144144
145+
If the indexes have names, you can use the level names instead of specifying
146+
the level numbers:
147+
148+
.. ipython:: python
149+
150+
stacked.unstack('second')
151+
145152
These functions are very intelligent about handling missing data and do not
146153
expect each subgroup within the hierarchical index to have the same set of
147154
labels. They also can handle the index being unsorted (but you can make it
@@ -150,7 +157,8 @@ sorted by calling ``sortlevel``, of course). Here is a more complex example:
150157
.. ipython:: python
151158
152159
columns = MultiIndex.from_tuples([('A', 'cat'), ('B', 'dog'),
153-
('B', 'cat'), ('A', 'dog')])
160+
('B', 'cat'), ('A', 'dog')],
161+
names=['exp', 'animal'])
154162
df = DataFrame(randn(8, 4), index=index, columns=columns)
155163
df2 = df.ix[[0, 1, 2, 4, 5, 7]]
156164
df2
@@ -160,8 +168,8 @@ which level in the columns to stack:
160168

161169
.. ipython:: python
162170
163-
df2.stack(1)
164-
df2.stack(0)
171+
df2.stack('exp')
172+
df2.stack('animal')
165173
166174
Unstacking when the columns are a ``MultiIndex`` is also careful about doing
167175
the right thing:

pandas/core/common.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
# XXX: HACK for NumPy 1.5.1 to suppress warnings
1717
try:
1818
np.seterr(all='ignore')
19+
np.set_printoptions(suppress=True)
1920
except Exception: # pragma: no cover
2021
pass
2122

0 commit comments

Comments
 (0)