You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Apply changes proposed by @deppen8 in #468, but without styling "pandas" with backticks.
- Add lots of code style formatting where appropriate
- Replace references to isnull() with isna(). These methods are exactly the same for pandas, but isna() is consistent with fillna, dropna, etc.
- Replace a reference to merged_left.genus with merged_left['genus'], the preferred notation style for pandas
- Add more consistent use of {: .output} formatting
- Remove u'string' notation, which is a Python 2.x leftover, to match what learners will see with Python 3.x
Co-authored-by: Toby Hodges <tobyhodges@carpentries.org>
Co-authored-by: Jacob Deppen <deppen.8@gmail.com>
To work through the examples below, we first need to load the species and
27
-
surveys files into pandas DataFrames. In iPython:
27
+
surveys files into pandas DataFrames. In a Jupyter Notebook or iPython:
28
28
29
29
~~~
30
30
import pandas as pd
31
31
surveys_df = pd.read_csv("data/surveys.csv",
32
32
keep_default_na=False, na_values=[""])
33
33
surveys_df
34
+
~~~
35
+
{: .language-python}
34
36
37
+
~~~
35
38
record_id month day year plot species sex hindfoot_length weight
36
39
0 1 7 16 1977 2 NA M 32 NaN
37
40
1 2 7 16 1977 3 NA M 33 NaN
@@ -46,10 +49,17 @@ surveys_df
46
49
35548 35549 12 31 2002 5 NaN NaN NaN NaN
47
50
48
51
[35549 rows x 9 columns]
52
+
~~~
53
+
{: .output}
49
54
55
+
~~~
50
56
species_df = pd.read_csv("data/species.csv",
51
57
keep_default_na=False, na_values=[""])
52
58
species_df
59
+
~~~
60
+
{: .language-python}
61
+
62
+
~~~
53
63
species_id genus species taxa
54
64
0 AB Amphispiza bilineata Bird
55
65
1 AH Ammospermophilus harrisi Rodent
@@ -65,14 +75,14 @@ species_df
65
75
66
76
[54 rows x 4 columns]
67
77
~~~
68
-
{: .language-python}
78
+
{: .output}
69
79
70
80
Take note that the `read_csv` method we used can take some additional options which
71
81
we didn't use previously. Many functions in Python have a set of options that
72
82
can be set by the user if needed. In this case, we have told pandas to assign
73
-
empty values in our CSV to NaN`keep_default_na=False, na_values=[""]`.
83
+
empty values in our CSV to `NaN` with the parameters `keep_default_na=False` and `na_values=[""]`.
74
84
We have explicitly requested to change empty values in the CSV to NaN,
75
-
this is however also the default behaviour of `read_csv`.
85
+
this is however also the default behaviour of `read_csv`.
76
86
[More about all of the `read_csv` options here and their defaults.](https://pandas.pydata.org/pandas-docs/stable/reference/api/pandas.read_csv.html#pandas.read_csv)
0 commit comments