Skip to content

DOC: Reindexing behaviour of dataframe column-assignment missing #40985

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

Closed
wants to merge 24 commits into from
Closed
Changes from 21 commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
89259db
if/else changes test
Mar 19, 2021
eda20a1
Series.between changes to inclusive boundaries
Mar 21, 2021
7af55a7
changes to date_range parameters
Mar 24, 2021
85a33cc
Changed series.between error handling to throw value error instead of…
Mar 24, 2021
c87e240
changes to series.between documentation and error message
Mar 24, 2021
cc6b24d
Merge pull request #1 from hewittk/new-boundary-inputs
hewittk Mar 25, 2021
4ebfa59
parameters as either booleans or strings
Mar 25, 2021
438f1ba
Merge pull request #2 from hewittk/new-boundary-inputs
hewittk Mar 25, 2021
e81e420
addition of new examples in indexing.py
mmarconi Apr 14, 2021
fc4afe6
Added general example of adding column using series
Apr 16, 2021
14fb6ab
Made examples specific to .loc[]
Apr 16, 2021
fce9b2d
Remove changes made from copied previous files
Apr 16, 2021
05277f2
Removed minor changes remaining from copied previous files
Apr 16, 2021
ca03c5c
Wording about Series being aligned to dataframe in partial column exa…
Apr 18, 2021
b9a515e
Information about series alignment to index of DataFrame
Apr 24, 2021
95f8673
Warning about using df.loc to assign a column
Apr 24, 2021
fccfad8
Reword warning
May 3, 2021
855c48e
Rollback to commit with passing tests
May 3, 2021
898a524
More detailed information about series alignment
May 3, 2021
72aea9d
Warning on using df.loc[:, 'shield'] to assign a column
May 4, 2021
6a928ed
New format of warning
May 5, 2021
3a80d54
Merge branch 'pandas-dev:master' into issue39845-column-indexing
hewittk Jun 9, 2021
6441a52
Move warning to loc method head and higher example
hewittk Jun 9, 2021
669a6b3
Fix pep8 issues
hewittk Jun 9, 2021
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
34 changes: 34 additions & 0 deletions pandas/core/indexing.py
Original file line number Diff line number Diff line change
Expand Up @@ -443,6 +443,40 @@ def loc(self) -> _LocIndexer:
8 4 5
9 7 8

**Setting values using Series**

Assign column using Series

.. warning::
Preferred syntax to assign a column: `df['shield']` instead
of allocation through `df.loc[]`

>>> df.loc[:, 'shield'] = pd.Series({7: 8, 8: 10, 9: 13})
>>> df
max_speed shield
7 1 8
8 4 10
9 7 13

Assigning column to a Series with non matching indexes aligns the
right hand side to the index of the left

>>> df.loc[:, 'shield'] = pd.Series({8: 10})
>>> df
max_speed shield
7 1 NaN
8 4 10.0
9 7 NaN

Assign column containing value with missing index

>>> df.loc[:, 'shield'] = pd.Series({11: 14})
>>> df
max_speed shield
7 1 NaN
8 4 NaN
9 7 NaN

**Getting values with a MultiIndex**

A number of examples using a DataFrame with a MultiIndex
Expand Down