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
Copy file name to clipboardExpand all lines: modules/module1/slides/module1_29.qmd
+5-13Lines changed: 5 additions & 13 deletions
Original file line number
Diff line number
Diff line change
@@ -77,27 +77,19 @@ Now we can use `.value_counts()` on this `mfr_column` variable to reference it,
77
77
---
78
78
79
79
```{python}
80
-
mfr_col_wrong = cereal[['mfr']]
81
-
mfr_col_wrong
80
+
mfr_col_dataframe = cereal[['mfr']]
81
+
mfr_col_dataframe
82
82
```
83
83
84
84
<br>
85
85
86
-
```python
87
-
mfr_col_wrong.value_counts()
86
+
```{python}
87
+
mfr_col_dataframe.value_counts()
88
88
```
89
89
90
-
```out
91
-
AttributeError: 'DataFrame' object has no attribute 'value_counts'
92
-
93
-
Detailed traceback:
94
-
File "<string>", line 1, in <module>
95
-
File "/usr/local/lib/python3.7/site-packages/pandas/core/generic.py", line 5274, in __getattr__
96
-
return object.__getattribute__(self, name)
97
-
```
98
90
99
91
:::{.notes}
100
-
If we did instead use double square brackets with `pd.value_counts()`, we would get an error. So it is important to take care and remember when you are using `value_counts()`, you only use one set of square brackets.
92
+
`value_counts()` can also be called on a DataFrame to count unique rows.
0 commit comments