Skip to content
Open
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
2 changes: 1 addition & 1 deletion episodes/01-short-introduction-to-Python.md
Original file line number Diff line number Diff line change
Expand Up @@ -529,7 +529,7 @@ print(rev)
```

```output
{1: 'one', 2: 'apple-sauce', 3: 'three'}
{'first': 'one', 'second': 2, 'third': 'three', 2: 'apple-sauce'}
```

:::::::::::::::::::::::::::::::::::
Expand Down
2 changes: 1 addition & 1 deletion episodes/02-starting-with-data.md
Original file line number Diff line number Diff line change
Expand Up @@ -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"})
```

::::::::::::::::::::::::::::::::::
Expand Down
4 changes: 2 additions & 2 deletions episodes/04-data-types-and-format.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
7 changes: 3 additions & 4 deletions episodes/05-merging-data.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
9 changes: 5 additions & 4 deletions episodes/06-loops-and-functions.md
Original file line number Diff line number Diff line change
Expand Up @@ -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']))
Expand Down Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion episodes/07-visualization-ggplot-python.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion episodes/08-putting-it-all-together.md
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand Down
2 changes: 1 addition & 1 deletion episodes/09-working-with-sql.md
Original file line number Diff line number Diff line change
Expand Up @@ -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")

Expand Down
2 changes: 1 addition & 1 deletion learners/setup.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down