Skip to content

Update indexing.rst #7188

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

Merged
merged 1 commit into from
May 20, 2014
Merged
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
10 changes: 7 additions & 3 deletions doc/source/indexing.rst
Original file line number Diff line number Diff line change
Expand Up @@ -206,15 +206,19 @@ as an attribute:
dfa.A
panel.one

Setting is allowed as well
You can use attribute access to modify an existing element of a Series or column of a DataFrame, but be careful;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe move these couple of lines to an actual .. warning:: see below

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I considered that but thought this was enough of a gotcha that I wanted to
keep the warning right there with the problematic example.

But I am willing to be overruled.

On Tue, May 20, 2014 at 3:01 PM, jreback [email protected] wrote:

In doc/source/indexing.rst:

@@ -206,15 +206,19 @@ as an attribute:
dfa.A
panel.one

-Setting is allowed as well
+You can use attribute access to modify an existing element of a Series or column of a DataFrame, but be careful;

maybe move these couple of lines to an actual .. warning:: see below


Reply to this email directly or view it on GitHubhttps://github.com//pull/7188/files#r12861818
.

if you try to use attribute access to create a new column, it fails silently, creating a new attribute rather than a
new column.

.. ipython:: python

sa.a = 5
sa
dfa.A = list(range(len(dfa.index)))
dfa.A = list(range(len(dfa.index))) # ok if A already exists
dfa

dfa['A'] = list(range(len(dfa.index))) # use this form to create a new column
dfa

.. warning::

- You can use this access only if the index element is a valid python identifier, e.g. ``s.1`` is not allowed.
Expand Down