Open utterances-bot opened 3 years ago
For: "data.loc['Denmark',:]" --> why do you need "a ,:" ? I get the same results without...
For: "data['gdpPercap_2007']/data['gdpPercap_1952']" --> How does the program know that he should calculate this for all countries and not just one row?
For: "data['gdpPercap_2007']/data['gdpPercap_1952']" --> Why not use the ".loc" ?
There are two typos in this code: my_string = 'Hello world!' # creation of a string object dir(myString) --> dir(my_string)
Python includes a dir() function that can be used to display all of the available methods (functions) that are built into a data object. --> As it states "data object" where is this list depending on or is it universal?
@thoTUM86 good questions
I just wrote a comment here and it disappeared.
@cforgaci hmmm that is really strange! I don't see it anywhere, sorry that happened!
@aecryan, no problem, but it's too long to reproduce. This is a good reminder to write answers in a separate markdown editor :)
Hahaha I fully respect that. And, yes better safe than sorry!
Trying again @cforgaci comment, that appears in github issues but not in the website: 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)
@jurra, thanks, now I can see it!
I post here my answer: 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.
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