-
-
Notifications
You must be signed in to change notification settings - Fork 18.4k
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
Closed
Changes from all commits
Commits
Show all changes
24 commits
Select commit
Hold shift + click to select a range
89259db
if/else changes test
eda20a1
Series.between changes to inclusive boundaries
7af55a7
changes to date_range parameters
85a33cc
Changed series.between error handling to throw value error instead of…
c87e240
changes to series.between documentation and error message
cc6b24d
Merge pull request #1 from hewittk/new-boundary-inputs
hewittk 4ebfa59
parameters as either booleans or strings
438f1ba
Merge pull request #2 from hewittk/new-boundary-inputs
hewittk e81e420
addition of new examples in indexing.py
mmarconi fc4afe6
Added general example of adding column using series
14fb6ab
Made examples specific to .loc[]
fce9b2d
Remove changes made from copied previous files
05277f2
Removed minor changes remaining from copied previous files
ca03c5c
Wording about Series being aligned to dataframe in partial column exa…
b9a515e
Information about series alignment to index of DataFrame
95f8673
Warning about using df.loc to assign a column
fccfad8
Reword warning
855c48e
Rollback to commit with passing tests
898a524
More detailed information about series alignment
72aea9d
Warning on using df.loc[:, 'shield'] to assign a column
6a928ed
New format of warning
3a80d54
Merge branch 'pandas-dev:master' into issue39845-column-indexing
hewittk 6441a52
Move warning to loc method head and higher example
hewittk 669a6b3
Fix pep8 issues
hewittk File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -287,6 +287,10 @@ def loc(self) -> _LocIndexer: | |
- An alignable boolean Series. The index of the key will be aligned before | ||
masking. | ||
- An alignable Index. The Index of the returned selection will be the input. | ||
|
||
.. warning:: Preferred syntax to assign a column: `df[]` instead of | ||
allocation through `df.loc[]` | ||
|
||
- A ``callable`` function with one argument (the calling Series or | ||
DataFrame) and that returns valid output for indexing (one of the above) | ||
|
||
|
@@ -388,6 +392,9 @@ def loc(self) -> _LocIndexer: | |
|
||
**Setting values** | ||
|
||
.. warning:: Preferred syntax to assign a column: `df['shield']` | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same |
||
instead of allocation through `df.loc[]` such as `df.loc['shield']` | ||
|
||
Set value for all items matching the list of labels | ||
|
||
>>> df.loc[['viper', 'sidewinder'], ['shield']] = 50 | ||
|
@@ -445,6 +452,36 @@ def loc(self) -> _LocIndexer: | |
8 4 5 | ||
9 7 8 | ||
|
||
**Setting values using Series** | ||
hewittk marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
Assign column using Series | ||
|
||
>>> 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 | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this true? I didn't find note of this in the original issue?