-
-
Notifications
You must be signed in to change notification settings - Fork 18.4k
Added example to Dataframe.get docs #43233
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
MarcoGorelli
merged 6 commits into
pandas-dev:master
from
oovk:adding-example-Dataframe.get
Aug 27, 2021
Merged
Changes from 3 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
05937e9
added example to Dataframe.get
oovk b3e2cf3
Merge remote-tracking branch 'upstream/master' into adding-example-Da…
oovk 7e68173
added example for default param in dataframe.get doc
oovk 0b7cdba
made suggested changes in dataframe.get example
oovk feaa214
more changes
oovk e01ca6d
fixup
MarcoGorelli 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 | ||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -3991,6 +3991,38 @@ def get(self, key, default=None): | |||||||||||||
Returns | ||||||||||||||
------- | ||||||||||||||
value : same type as items contained in object | ||||||||||||||
|
||||||||||||||
Examples | ||||||||||||||
-------- | ||||||||||||||
>>> df = pd.DataFrame([[24.3, 75.7, 'high'], | ||||||||||||||
... [31, 87.8, 'high'], | ||||||||||||||
... [22, 71.6, 'medium'], | ||||||||||||||
... [35, 95, 'medium']], | ||||||||||||||
... columns=['temp_celsius', 'temp_fahrenheit', | ||||||||||||||
... 'windspeed'], | ||||||||||||||
... index=pd.date_range(start='2014-02-12', | ||||||||||||||
... end='2014-02-15', freq='D')) | ||||||||||||||
|
||||||||||||||
>>> df | ||||||||||||||
temp_celsius temp_fahrenheit windspeed | ||||||||||||||
2014-02-12 24.3 75.7 high | ||||||||||||||
2014-02-13 31.0 87.8 high | ||||||||||||||
2014-02-14 22.0 71.6 medium | ||||||||||||||
2014-02-15 35.0 95.0 medium | ||||||||||||||
|
||||||||||||||
>>> df1 = df.get(["temp_celsius","windspeed"]) | ||||||||||||||
|
||||||||||||||
>>> df1 | ||||||||||||||
temp_celsius windspeed | ||||||||||||||
2014-02-12 24.3 high | ||||||||||||||
2014-02-13 31.0 high | ||||||||||||||
2014-02-14 22.0 medium | ||||||||||||||
2014-02-15 35.0 medium | ||||||||||||||
|
||||||||||||||
>>> df2 = df.get(["temp_celsius","temp_kelvin"], default = "default_value") | ||||||||||||||
|
||||||||||||||
>>> df2 | ||||||||||||||
'default_value' | ||||||||||||||
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. likewise, and dedent the result
Suggested change
|
||||||||||||||
""" | ||||||||||||||
try: | ||||||||||||||
return self[key] | ||||||||||||||
|
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.
no need to assign to a new variable, let's just print the first one