Skip to content

Commit be45e0d

Browse files
Merge pull request #7188 from AllenDowney/patch-1
Update indexing.rst
2 parents 0535192 + 54dd2a1 commit be45e0d

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

doc/source/indexing.rst

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -206,15 +206,19 @@ as an attribute:
206206
dfa.A
207207
panel.one
208208
209-
Setting is allowed as well
209+
You can use attribute access to modify an existing element of a Series or column of a DataFrame, but be careful;
210+
if you try to use attribute access to create a new column, it fails silently, creating a new attribute rather than a
211+
new column.
210212

211213
.. ipython:: python
212214
213215
sa.a = 5
214216
sa
215-
dfa.A = list(range(len(dfa.index)))
217+
dfa.A = list(range(len(dfa.index))) # ok if A already exists
216218
dfa
217-
219+
dfa['A'] = list(range(len(dfa.index))) # use this form to create a new column
220+
dfa
221+
218222
.. warning::
219223

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

0 commit comments

Comments
 (0)