Skip to content
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

628 explicit df names #654

Merged
merged 3 commits into from
Jul 24, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions episodes/08-data-frames.md
Original file line number Diff line number Diff line change
Expand Up @@ -333,7 +333,7 @@ and the Gapminder GDP data for Europe has been loaded:
```python
import pandas as pd

df = pd.read_csv('data/gapminder_gdp_europe.csv', index_col='country')
data_europe = pd.read_csv('data/gapminder_gdp_europe.csv', index_col='country')
```

Write an expression to find the Per Capita GDP of Serbia in 2007.
Expand All @@ -345,7 +345,7 @@ Write an expression to find the Per Capita GDP of Serbia in 2007.
The selection can be done by using the labels for both the row ("Serbia") and the column ("gdpPercap\_2007"):

```python
print(df.loc['Serbia', 'gdpPercap_2007'])
print(data_europe.loc['Serbia', 'gdpPercap_2007'])
```

The output is
Expand All @@ -367,8 +367,8 @@ The output is
what rule governs what is included (or not) in numerical slices and named slices in Pandas?

```python
print(df.iloc[0:2, 0:2])
print(df.loc['Albania':'Belgium', 'gdpPercap_1952':'gdpPercap_1962'])
print(data_europe.iloc[0:2, 0:2])
print(data_europe.loc['Albania':'Belgium', 'gdpPercap_1952':'gdpPercap_1962'])
```

::::::::::::::: solution
Expand Down
14 changes: 7 additions & 7 deletions episodes/16-writing-functions.md
Original file line number Diff line number Diff line change
Expand Up @@ -458,8 +458,8 @@ Assume that the following code has been executed:
```python
import pandas as pd

df = pd.read_csv('data/gapminder_gdp_asia.csv', index_col=0)
japan = df.loc['Japan']
data_asia = pd.read_csv('data/gapminder_gdp_asia.csv', index_col=0)
japan = data_asia.loc['Japan']
```

1. Complete the statements below to obtain the average GDP for Japan
Expand All @@ -475,7 +475,7 @@ japan = df.loc['Japan']

```python
def avg_gdp_in_decade(country, continent, year):
df = pd.read_csv('data/gapminder_gdp_'+___+'.csv',delimiter=',',index_col=0)
data_countries = pd.read_csv('data/gapminder_gdp_'+___+'.csv',delimiter=',',index_col=0)
____
____
____
Expand Down Expand Up @@ -504,8 +504,8 @@ japan = df.loc['Japan']

```python
def avg_gdp_in_decade(country, continent, year):
df = pd.read_csv('data/gapminder_gdp_' + continent + '.csv', index_col=0)
c = df.loc[country]
data_countries = pd.read_csv('data/gapminder_gdp_' + continent + '.csv', index_col=0)
c = data_countries.loc[country]
gdp_decade = 'gdpPercap_' + str(year // 10)
avg = (c.loc[gdp_decade + '2'] + c.loc[gdp_decade + '7'])/2
return avg
Expand All @@ -515,8 +515,8 @@ japan = df.loc['Japan']

```python
def avg_gdp_in_decade(country, continent, year):
df = pd.read_csv('data/gapminder_gdp_' + continent + '.csv', index_col=0)
c = df.loc[country]
data_countries = pd.read_csv('data/gapminder_gdp_' + continent + '.csv', index_col=0)
c = data_countries.loc[country]
gdp_decade = 'gdpPercap_' + str(year // 10)
total = 0.0
num_years = 0
Expand Down
Loading