Skip to content

Commit 4f79301

Browse files
committed
differences for PR #691
1 parent 930918a commit 4f79301

File tree

2 files changed

+11
-3
lines changed

2 files changed

+11
-3
lines changed

14-looping-data-sets.md

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -207,13 +207,21 @@ for filename in glob.glob('data/gapminder_gdp*.csv'):
207207
# convenient abstractions for working with filesystem paths and could solve this as well:
208208
# from pathlib import Path
209209
# region = Path(filename).stem.split('_')[-1]
210-
region = filename.split('_')[-1][:-4]
210+
region = filename.split('_')[-1][:-4]
211+
# extract the years from the columns of the dataframe
212+
headings = dataframe.columns[1:]
213+
years = headings.str.split('_').str.get(1)
211214
# pandas raises errors when it encounters non-numeric columns in a dataframe computation
212215
# but we can tell pandas to ignore them with the `numeric_only` parameter
213216
dataframe.mean(numeric_only=True).plot(ax=ax, label=region)
214217
# NOTE: another way of doing this selects just the columns with gdp in their name using the filter method
215218
# dataframe.filter(like="gdp").mean().plot(ax=ax, label=region)
216-
219+
# set the title and labels
220+
ax.set_title('GDP Per Capita for Regions Over Time')
221+
ax.set_xticks(range(len(years)))
222+
ax.set_xticklabels(years)
223+
ax.set_xlabel('Year')
224+
plt.tight_layout()
217225
plt.legend()
218226
plt.show()
219227
```

md5sum.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
"episodes/11-lists.md" "1257daeb542377a3b04c6bec0d0ffee1" "site/built/11-lists.md" "2023-07-24"
1818
"episodes/12-for-loops.md" "1da6e4e57a25f8d4fd64802c2eb682c4" "site/built/12-for-loops.md" "2023-05-02"
1919
"episodes/13-conditionals.md" "2739086f688f386c32ce56400c6b27e2" "site/built/13-conditionals.md" "2024-02-16"
20-
"episodes/14-looping-data-sets.md" "fb2992c34b244b375302ffb15bd25b8d" "site/built/14-looping-data-sets.md" "2024-03-05"
20+
"episodes/14-looping-data-sets.md" "9893b774bd5d583592d39a66f69ea68a" "site/built/14-looping-data-sets.md" "2024-12-03"
2121
"episodes/15-coffee.md" "062bae79eb17ee57f183b21658a8d813" "site/built/15-coffee.md" "2023-05-02"
2222
"episodes/16-writing-functions.md" "a87b7fd96770bd8c24d695ef529b93ce" "site/built/16-writing-functions.md" "2024-06-13"
2323
"episodes/17-scope.md" "8109afb18f278a482083d867ad80da6e" "site/built/17-scope.md" "2023-05-02"

0 commit comments

Comments
 (0)