swcarpentry / python-novice-gapminder

Plotting and Programming in Python
http://swcarpentry.github.io/python-novice-gapminder/
Other
163 stars 428 forks source link

replace `str.strip()` with `str.replace()` #623

Closed n2ygk closed 1 year ago

n2ygk commented 1 year ago

str.strip() actually removes each character in the character class string. So .strip('gpdaPerc_') would also do the same thing and is confusing. I made a live typo during the workshop and a student asked me how was it that it still worked when I had typed gdp_Percap_ even though there's no _ between gdp and Per!

Reference: https://pandas.pydata.org/docs/reference/api/pandas.Series.str.strip.html and https://pandas.pydata.org/docs/reference/api/pandas.Series.str.replace.html

vahtras commented 1 year ago

Thanks that makes sense to me

On Fri, Jan 13, 2023, 22:13 Alan Crosswell @.***> wrote:

str.strip() actually removes each character in the character class string. So .strip('gpdaPerc_') would also do the same thing and is confusing. I made a live typo during the workshop and a student asked me how was it that it still worked when I had add gdpPercap even though there's no _ between gdp and Per!

Reference: https://pandas.pydata.org/docs/reference/api/pandas.Series.str.strip.html and https://pandas.pydata.org/docs/reference/api/pandas.Series.str.replace.html

You can view, comment on, or merge this pull request online at:

https://github.com/swcarpentry/python-novice-gapminder/pull/623 Commit Summary

File Changes

(1 file https://github.com/swcarpentry/python-novice-gapminder/pull/623/files)

Patch Links:

— Reply to this email directly, view it on GitHub https://github.com/swcarpentry/python-novice-gapminder/pull/623, or unsubscribe https://github.com/notifications/unsubscribe-auth/ABLLJBPUR6KWGWGLM5T6SDDWSHAQJANCNFSM6AAAAAAT22KZ2Y . You are receiving this because you are subscribed to this thread.Message ID: @.***>

n2ygk commented 1 year ago

thanks for catching this! Looking more closely at this section makes me realize there are a few more areas that could use improvement:

I'm happy to add the changes in but if you have time to also include them it would be much appreciated!

@alee so this fragment is in a python code comment (not markdown text). I guess I'll add the links to the bullet list above the code.