Skip to content

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
merged 6 commits into from
Aug 27, 2021

Conversation

oovk
Copy link
Contributor

@oovk oovk commented Aug 26, 2021

  • closes #xxxx
  • tests added / passed
  • Ensure all linting tests pass, see here for how to run them
  • whatsnew entry
    @MarcoGorelli

Copy link
Member

@MarcoGorelli MarcoGorelli left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for your PR - could you make the example one such that it shows the use of the default argument?

@oovk
Copy link
Contributor Author

oovk commented Aug 27, 2021

you mean this one right? @MarcoGorelli

df2 = df1.get("key") #key column is not available in dataframe 
print(df2)
None #Returns default value if not found.

@debnathshoham
Copy link
Member

debnathshoham commented Aug 27, 2021

I think, something like this (df is directly from the example you added)

In [9]: df.get(["temp_celsius","windspeed","temp_Kelvin"], default = "Some column missing")
Out[9]: 'Some column missing'

@MarcoGorelli
Copy link
Member

@oovk
Copy link
Contributor Author

oovk commented Aug 27, 2021

yes. Tested the validate_docstrings and python make.py clean, python make.py --single pandas.DataFrame.get

Copy link
Member

@MarcoGorelli MarcoGorelli left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

couple of comments, other than that looks good

Comment on lines 4013 to 4020
>>> 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
Copy link
Member

@MarcoGorelli MarcoGorelli Aug 27, 2021

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

Suggested change
>>> 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
>>> df.get(["temp_celsius", "windspeed"])
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

Comment on lines 4022 to 4025
>>> df2 = df.get(["temp_celsius","temp_kelvin"], default = "default_value")

>>> df2
'default_value'
Copy link
Member

@MarcoGorelli MarcoGorelli Aug 27, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

likewise, and dedent the result

Suggested change
>>> df2 = df.get(["temp_celsius","temp_kelvin"], default = "default_value")
>>> df2
'default_value'
>>> df.get(["temp_celsius", "temp_kelvin"], default = "default_value")
'default_value'

@MarcoGorelli
Copy link
Member

These errors from validate_docstrings need fixing:

	flake8 error: E231 missing whitespace after ','
2     E251 unexpected spaces around keyword / parameter equals (2 times)

check https://www.python.org/dev/peps/pep-0008/

@MarcoGorelli MarcoGorelli added this to the 1.4 milestone Aug 27, 2021
Copy link
Member

@MarcoGorelli MarcoGorelli left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@MarcoGorelli MarcoGorelli merged commit b5e4e2e into pandas-dev:master Aug 27, 2021
@oovk
Copy link
Contributor Author

oovk commented Aug 27, 2021

@MarcoGorelli How did you remove those errors? I have tried using autopep8 in vscode, It did nothing for me. Can u please explain a bit?

feefladder pushed a commit to feefladder/pandas that referenced this pull request Sep 7, 2021
* added example to Dataframe.get

* added example for default param in dataframe.get doc

* made suggested changes in dataframe.get example

* more changes

* fixup

Co-authored-by: Marco Gorelli <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants