diff --git a/episodes/01-short-introduction-to-Python.md b/episodes/01-short-introduction-to-Python.md index e13dffeaa..408bd03c6 100644 --- a/episodes/01-short-introduction-to-Python.md +++ b/episodes/01-short-introduction-to-Python.md @@ -529,7 +529,7 @@ print(rev) ``` ```output -{1: 'one', 2: 'apple-sauce', 3: 'three'} +{'first': 'one', 'second': 2, 'third': 'three', 2: 'apple-sauce'} ``` ::::::::::::::::::::::::::::::::::: diff --git a/episodes/02-starting-with-data.md b/episodes/02-starting-with-data.md index f2a6eb6db..3e61d0746 100644 --- a/episodes/02-starting-with-data.md +++ b/episodes/02-starting-with-data.md @@ -379,7 +379,7 @@ Show that the DataFrame index Adapting the name is done with the `rename` function: ```python -surveys_df.rename(columns={"plot_id": "plotid"})`) +surveys_df.rename(columns={"plot_id": "plotid"}) ``` :::::::::::::::::::::::::::::::::: diff --git a/episodes/04-data-types-and-format.md b/episodes/04-data-types-and-format.md index 7a930e9f3..0e60f5caa 100644 --- a/episodes/04-data-types-and-format.md +++ b/episodes/04-data-types-and-format.md @@ -195,7 +195,7 @@ print(10/3) ``` We can also convert a floating point number to an integer or an integer to -floating point number. Notice that Python by default rounds down when it +floating point number. Notice that Python truncates towards zero when it converts from floating point to integer. ```python @@ -471,7 +471,7 @@ What we've learned: -[datetime]: https://doc.python.org/2/library/datetime.html +[datetime]: https://docs.python.org/3/library/datetime.html :::::::::::::::::::::::::::::::::::::::: keypoints diff --git a/episodes/05-merging-data.md b/episodes/05-merging-data.md index 5384bb174..e8cb70927 100644 --- a/episodes/05-merging-data.md +++ b/episodes/05-merging-data.md @@ -441,10 +441,9 @@ The pandas `merge` function supports other join types: rows from the `left` DataFrame without matching join key(s) values are discarded. - Full (outer) join: Invoked by passing `how='outer'` as an argument. This join - type returns the all pairwise combinations of rows from both DataFrames; i.e., the - *Cartesian product* and the result DataFrame will use `NaN` where data is missing in one - of the dataframes. This join type is very rarely used, but can be helpful to see all - the qualities of both tables, including each common and duplicate column. + type keeps all join keys from both DataFrames, combining rows with matching keys. + The result DataFrame will use `NaN` where a key has no match in one of the + DataFrames. A Cartesian product, in contrast, is produced by `how='cross'`. - Self-join: Joins a data frame with itself. Self-joins can be useful when you want to, for instance, compare records within the same dataset based on a given criteria. A fuller discussion of how and when it might be useful to do so can be found in [Self-Join and Cross Join in Pandas DataFrame](https://blog.devgenius.io/self-join-and-cross-join-in-pandas-dataframe-b30bfbc0e52a) diff --git a/episodes/06-loops-and-functions.md b/episodes/06-loops-and-functions.md index d4a7aaa4b..3f0d6e78d 100644 --- a/episodes/06-loops-and-functions.md +++ b/episodes/06-loops-and-functions.md @@ -1065,7 +1065,7 @@ HINT: you can create a loop with a list as follows: `for years in year_list:` # Select data for the year surveys_year = all_data[all_data.year == this_year] if len(surveys_year) == 0: # 'if not len(surveys_year):' will also work - print('no data available for ' + this_year + ', output file not created') + print('no data available for ' + str(this_year) + ', output file not created') else: # Write the new DataFrame to a csv file filename = os.path.join(folder_to_save, ''.join([root_name, str(this_year), '.csv'])) @@ -1093,18 +1093,19 @@ HINT: you can create a loop with a list as follows: `for years in year_list:` # Select data for the year surveys_year = all_data[all_data.year == this_year] if len(surveys_year) == 0: - print('no data available for ' + this_year + ', output file not created') + print('no data available for ' + str(this_year) + ', output file not created') else: - if folder_to_save not in os.listdir('.'): + if not os.path.isdir(folder_to_save): os.mkdir(folder_to_save) print('Processed directory created') # Write the new DataFrame to a csv file filename = os.path.join(folder_to_save, ''.join([root_name, str(this_year), '.csv'])) surveys_year.to_csv(filename) + return filename ``` The equivalent, without using `not` to invert the conditional, would be: ```python - if folder_to_save in os.listdir('.'): + if os.path.isdir(folder_to_save): pass else: os.mkdir(folder_to_save) diff --git a/episodes/07-visualization-ggplot-python.md b/episodes/07-visualization-ggplot-python.md index 89761d618..7c132eb42 100644 --- a/episodes/07-visualization-ggplot-python.md +++ b/episodes/07-visualization-ggplot-python.md @@ -634,7 +634,7 @@ my_plot.save("scatterplot.png", width=10, height=10, dpi=300) [plotnine]: https://github.com/has2k1/plotnine?tab=readme-ov-file [ggplot2]: https://ggplot2.tidyverse.org [grammar-of-graphics]: https://link.springer.com/book/10.1007%2F0-387-28695-0 -[setup-plotnine]: https://datacarpentry.org/python-ecology-lesson/#required-python-packages +[setup-plotnine]: ../learners/setup.md#required-python-packages [plotnine-api]: https://plotnine.org/reference/ [ggplot2-cheat-sheet]: https://rstudio.github.io/cheatsheets/html/data-visualization.html diff --git a/episodes/08-putting-it-all-together.md b/episodes/08-putting-it-all-together.md index 24b84018e..197024f36 100644 --- a/episodes/08-putting-it-all-together.md +++ b/episodes/08-putting-it-all-together.md @@ -291,7 +291,7 @@ discharge = pd.read_csv("data/bouldercreek_09_2013.txt", "timezone", "flow_rate", "discharge_cd"]) discharge["datetime"] = pd.to_datetime(discharge["datetime"]) flood = discharge[(discharge["datetime"] >= "2013-09-11") & - (discharge["datetime"] <= "2013-09-15")] + (discharge["datetime"] < "2013-09-16")] fig, ax = plt.subplots() diff --git a/episodes/09-working-with-sql.md b/episodes/09-working-with-sql.md index 05afb3db4..130f0507c 100644 --- a/episodes/09-working-with-sql.md +++ b/episodes/09-working-with-sql.md @@ -238,7 +238,7 @@ con.close() df1 = pd.read_sql_query('SELECT surveys.year,plots.plot_type,species.genus,species.species,surveys.sex \ FROM surveys INNER JOIN plots ON surveys.plot = plots.plot_id INNER JOIN species ON \ surveys.species = species.species_id WHERE surveys.year>=1998 AND surveys.year<=2001 \ - AND ( surveys.sex = "M" OR surveys.sex = "F")') + AND ( surveys.sex = "M" OR surveys.sex = "F")', con) df1.to_sql("New Table 1", con, if_exists="replace") diff --git a/learners/setup.md b/learners/setup.md index af499a873..159c27b0a 100644 --- a/learners/setup.md +++ b/learners/setup.md @@ -199,7 +199,7 @@ jupyter notebook ``` The notebook should open automatically in your browser. If it does not or you -wish to use a different browser, open this link: [http://localhost:8888](https://localhost:8888). +wish to use a different browser, open this link: [http://localhost:8888](http://localhost:8888). ::: prereq ::::: ## Leave terminal used to launch Jupyter open