From 54dd2a1ae633d097f460f1b227b5119b038a7063 Mon Sep 17 00:00:00 2001 From: AllenDowney Date: Tue, 20 May 2014 14:55:26 -0400 Subject: [PATCH] Update indexing.rst Adding a warning, and example, about using attribute access to create a new column. --- doc/source/indexing.rst | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/doc/source/indexing.rst b/doc/source/indexing.rst index 322c58115de3c..1d25a395f74a9 100644 --- a/doc/source/indexing.rst +++ b/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; +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.