Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DOC: indexing.rst fixes w.r.t (GH8227) #8485

Merged
merged 1 commit into from
Oct 6, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
69 changes: 36 additions & 33 deletions doc/source/indexing.rst
Original file line number Diff line number Diff line change
Expand Up @@ -1191,39 +1191,8 @@ The name, if set, will be shown in the console display:
df
df['A']


Set operations on Index objects
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

.. _indexing.set_ops:

The three main operations are ``union (|)``, ``intersection (&)``, and ``diff
(-)``. These can be directly called as instance methods or used via overloaded
operators:

.. ipython:: python

a = Index(['c', 'b', 'a'])
b = Index(['c', 'e', 'd'])
a.union(b)
a | b
a & b
a - b

Also available is the ``sym_diff (^)`` operation, which returns elements
that appear in either ``idx1`` or ``idx2`` but not both. This is
equivalent to the Index created by ``(idx1 - idx2) + (idx2 - idx1)``,
with duplicates dropped.

.. ipython:: python

idx1 = Index([1, 2, 3, 4])
idx2 = Index([2, 3, 4, 5])
idx1.sym_diff(idx2)
idx1 ^ idx2

Setting index metadata (``name(s)``, ``levels``, ``labels``)
------------------------------------------------------------
Setting metadata
~~~~~~~~~~~~~~~~

.. versionadded:: 0.13.0

Expand Down Expand Up @@ -1261,6 +1230,40 @@ See :ref:`Advanced Indexing <advanced>` for usage of MultiIndexes.
index.levels[1]
index.set_levels(["a", "b"], level=1)

Set operations on Index objects
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

.. _indexing.set_ops:

.. warning::

In 0.15.0. the set operations ``+`` and ``-`` were deprecated in order to provide these for numeric type operations on certain
index types. ``+`` can be replace by ``.union()`` or ``|``, and ``-`` by ``.difference()``.

The two main operations are ``union (|)``, ``intersection (&)``
These can be directly called as instance methods or used via overloaded
operators. Difference is provided via the ``.difference()`` method.

.. ipython:: python

a = Index(['c', 'b', 'a'])
b = Index(['c', 'e', 'd'])
a | b
a & b
a.difference(b)

Also available is the ``sym_diff (^)`` operation, which returns elements
that appear in either ``idx1`` or ``idx2`` but not both. This is
equivalent to the Index created by ``idx1.difference(idx2).union(idx2.difference(idx1))``,
with duplicates dropped.

.. ipython:: python

idx1 = Index([1, 2, 3, 4])
idx2 = Index([2, 3, 4, 5])
idx1.sym_diff(idx2)
idx1 ^ idx2

Set / Reset Index
-----------------

Expand Down
2 changes: 1 addition & 1 deletion pandas/core/frame.py
Original file line number Diff line number Diff line change
Expand Up @@ -3752,7 +3752,7 @@ def append(self, other, ignore_index=False, verify_integrity=False):
'ignore_index=True')

index = None if other.name is None else [other.name]
combined_columns = self.columns.tolist() + (self.columns | other.index).difference(self.columns).tolist()
combined_columns = self.columns.tolist() + self.columns.union(other.index).difference(self.columns).tolist()
other = other.reindex(combined_columns, copy=False)
other = DataFrame(other.values.reshape((1, len(other))),
index=index, columns=combined_columns).convert_objects()
Expand Down