Open utterances-bot opened 3 years ago
Exercise: Selection of Individual Values
data.loc['Serbia','gdpPercap_2007']
get_gdp()
):
years = data.columns.str.strip('gdpPercap_').astype(int)
def get_gdp(country, year):
print("The GDP per capita of ", country, " in ", year, " was:\n", data.loc[country, years == year], sep='')
get_gdp("Serbia", 2007)
get_gdp("Hungary", 2007)
I don't know how to simplify the output of v2 to only show the year. Now it shows this:
The GDP per capita of Serbia in 2007 was:
gdpPercap_2007 9786.534714
Name: Serbia, dtype: float64
Exercise: Extent of Slicing
Exercise: Reconstructing Data
result.csv
Exercise: Selecting Indices
idxmin()
/idxmax()
displays the rowname (country) for the miminum / maximum values for each column, respectively. I noticed that the difference from min()
/max()
is that those display the value of minimum/maximum GDP, without specifyig the country, so idxmin()
/idxmax()
are more helpful in this sense.Note,myString
should be my_string
in the following code:
my_string = 'Hello world!' # creation of a string object
dir(myString)
@cforgaci here goes a version of the function where we can print only the gdp number:
def get_gdp(country, year):
gdp = data.loc[country, years == year]
print("The GDP per capita of ", country, " in ", year, " was:\n", gdp[0], sep='')
This specifies to get only the value in the series, this selection would only have one item, being at position 0.
@jurra, thanks! Ha, interesting, you received that message. I thought it was lost, as I cannot see it in the comments on the website.
On 16 Mar 2021, at 17:42, Jose Carlos Urra Llanusa @.***> wrote:
@cforgaci https://github.com/cforgaci here goes a version of the function where we can print only the gdp number:
def get_gdp(country, year): gdp = data.loc[country, years == year] print("The GDP per capita of ", country, " in ", year, " was:\n", gdp[0], sep='') — You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/the-magnificents/04-02-2021-Carpentry-for-HGIS/issues/75#issuecomment-800425205, or unsubscribe https://github.com/notifications/unsubscribe-auth/AIALFAAVVU2MTXXZNHSAPXTTD6C5ZANCNFSM4ZI3TRGQ.
@cforgaci Maybe you just have to refresh the page
@jurra, I tried, also restarted my browser. Actually, I cannot see your replies to this thread on the web page either. Is this only me?
On 16 Mar 2021, at 18:12, Jose Carlos Urra Llanusa @.***> wrote:
@cforgaci https://github.com/cforgaci Maybe you just have to refresh the page
— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/the-magnificents/04-02-2021-Carpentry-for-HGIS/issues/75#issuecomment-800449920, or unsubscribe https://github.com/notifications/unsubscribe-auth/AIALFAFJXVLR6BC6E4I32YLTD6GRLANCNFSM4ZI3TRGQ.
That is probably because somehow its being cached, and presenting you old versions of the website. If you try in an incognito window it should work.
@cforgaci I am wrong, actually I was expecting this behavior, but things are a bit more complex, the comments will show in the website only when they are written in the website.
Pandas dataframes — Python essentials for GIS learners
https://the-magnificents.github.io/04-02-2021-Carpentry-for-HGIS/02_Day_2_Python_GIS/exercise/B2_Exercise.html