Skip to content

Commit

Permalink
fixed tests and grammar
Browse files Browse the repository at this point in the history
  • Loading branch information
hayley committed Feb 19, 2020
1 parent 2f248a1 commit 89a5518
Show file tree
Hide file tree
Showing 3 changed files with 68 additions and 137 deletions.
6 changes: 3 additions & 3 deletions chapters/module1.md
Original file line number Diff line number Diff line change
Expand Up @@ -89,18 +89,18 @@ When you run a code exercise for the first time, it could take a bit of time for
- Import `pandas` as `pd`.
- Load in a dataset named `.csv`.
- Save the dataframe as `hockey_players`.
- display the first 5 rows of the dataframe
- Display the first 5 rows of the dataframe

<codeblock id="01_03a">

- Are you sure you are saving your dataframe as `hockey_players` a
- are you using `pd.read_csv()`
- Are you using `pd.read_csv()`

</codeblock>

- Now Let's display the column names of `hockey_players` and save it as `columns_hockey`.
- Save the number of rows `hockey_players` has in a variable called `hockey_rows`.
- the data frame dimension should be save as `hockey_dim`.
- The data frame dimension should be save as `hockey_dim`.


<codeblock id="01_03b">
Expand Down
2 changes: 1 addition & 1 deletion exercises/test_01_03a.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ def test():
# If an assertion fails, the message will be displayed

assert "import pandas" in __solution__ , "Are you using the right commands to import pandas?"
assert "read.csv" in __solution__ , "Are you reading in the data properly?"
assert "read_csv" in __solution__ , "Are you reading in the data properly?"
assert hockey_players.shape == (22, 10), "You may not have the correct dataset"
assert list(hockey_players.columns) == ['Player', 'No.', 'Age', 'Height', 'Weight', 'Country ', 'Position', 'Experience', 'Birth Date', 'Salary'], "Your column names does not seem correct"
__msg__.good("Nice work, well done!")
197 changes: 64 additions & 133 deletions slides/Untitled.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@
"cells": [
{
"cell_type": "code",
"execution_count": 24,
"metadata": {},
"execution_count": 7,
"metadata": {
"scrolled": true
},
"outputs": [
{
"data": {
Expand Down Expand Up @@ -379,174 +381,103 @@
"21 4 17-Aug-96 $1,500,000 "
]
},
"execution_count": 24,
"execution_count": 7,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"import pandas as pd\n",
"\n",
"import sys\n",
"df = pd.read_csv('../data/canucks.csv')\n",
"df"
]
},
{
"cell_type": "code",
"execution_count": 27,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"['Player',\n",
" 'No.',\n",
" 'Age',\n",
" 'Height',\n",
" 'Weight',\n",
" 'Country ',\n",
" 'Position',\n",
" 'Experience',\n",
" 'Birth Date',\n",
" 'Salary']"
]
},
"execution_count": 27,
"metadata": {},
"output_type": "execute_result"
}
],
"execution_count": null,
"metadata": {
"scrolled": true
},
"outputs": [],
"source": [
"list(df.columns)"
]
},
{
"cell_type": "code",
"execution_count": 21,
"execution_count": null,
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"<div>\n",
"<style scoped>\n",
" .dataframe tbody tr th:only-of-type {\n",
" vertical-align: middle;\n",
" }\n",
"\n",
" .dataframe tbody tr th {\n",
" vertical-align: top;\n",
" }\n",
"\n",
" .dataframe thead th {\n",
" text-align: right;\n",
" }\n",
"</style>\n",
"<table border=\"1\" class=\"dataframe\">\n",
" <thead>\n",
" <tr style=\"text-align: right;\">\n",
" <th></th>\n",
" <th>candy bar</th>\n",
" <th>chocolate</th>\n",
" <th>peanuts</th>\n",
" <th>caramel</th>\n",
" <th>nougat</th>\n",
" <th>cookie_wafer_rice</th>\n",
" <th>coconut</th>\n",
" <th>white_chocolate</th>\n",
" <th>multi</th>\n",
" <th>available_canada_america</th>\n",
" </tr>\n",
" </thead>\n",
" <tbody>\n",
" <tr>\n",
" <th>0</th>\n",
" <td>CoffeeCrisp</td>\n",
" <td>1</td>\n",
" <td>0</td>\n",
" <td>0</td>\n",
" <td>0</td>\n",
" <td>1</td>\n",
" <td>0</td>\n",
" <td>0</td>\n",
" <td>0</td>\n",
" <td>Canada</td>\n",
" </tr>\n",
" <tr>\n",
" <th>1</th>\n",
" <td>Butterfinger</td>\n",
" <td>1</td>\n",
" <td>1</td>\n",
" <td>1</td>\n",
" <td>0</td>\n",
" <td>0</td>\n",
" <td>0</td>\n",
" <td>0</td>\n",
" <td>0</td>\n",
" <td>America</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>\n",
"</div>"
],
"text/plain": [
" candy bar chocolate peanuts caramel nougat cookie_wafer_rice \\\n",
"0 CoffeeCrisp 1 0 0 0 1 \n",
"1 Butterfinger 1 1 1 0 0 \n",
"\n",
" coconut white_chocolate multi available_canada_america \n",
"0 0 0 0 Canada \n",
"1 0 0 0 America "
]
},
"execution_count": 21,
"metadata": {},
"output_type": "execute_result"
}
],
"outputs": [],
"source": [
"df.head(2)"
]
},
{
"cell_type": "code",
"execution_count": 25,
"execution_count": null,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"(22, 10)\n"
]
}
],
"outputs": [],
"source": [
"print(df.shape)"
]
},
{
"cell_type": "code",
"execution_count": 18,
"execution_count": null,
"metadata": {},
"outputs": [
{
"ename": "AttributeError",
"evalue": "'DataFrame' object has no attribute 'length'",
"output_type": "error",
"traceback": [
"\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
"\u001b[0;31mAttributeError\u001b[0m Traceback (most recent call last)",
"\u001b[0;32m<ipython-input-18-6c0e831f20c8>\u001b[0m in \u001b[0;36m<module>\u001b[0;34m\u001b[0m\n\u001b[0;32m----> 1\u001b[0;31m \u001b[0mdf\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mlength\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m",
"\u001b[0;32m//anaconda3/lib/python3.7/site-packages/pandas/core/generic.py\u001b[0m in \u001b[0;36m__getattr__\u001b[0;34m(self, name)\u001b[0m\n\u001b[1;32m 5177\u001b[0m \u001b[0;32mif\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0m_info_axis\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0m_can_hold_identifiers_and_holds_name\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mname\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 5178\u001b[0m \u001b[0;32mreturn\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0mname\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m-> 5179\u001b[0;31m \u001b[0;32mreturn\u001b[0m \u001b[0mobject\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0m__getattribute__\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mself\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mname\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 5180\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 5181\u001b[0m \u001b[0;32mdef\u001b[0m \u001b[0m__setattr__\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mself\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mname\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mvalue\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n",
"\u001b[0;31mAttributeError\u001b[0m: 'DataFrame' object has no attribute 'length'"
]
}
],
"outputs": [],
"source": [
"df.length"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"pandas_spec = importlib.util.find_spec(\"pandas\") \n",
"found = pandas_spec is not None"
]
},
{
"cell_type": "code",
"execution_count": 2,
"metadata": {},
"outputs": [],
"source": [
"import importlib\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"found"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"pandas_spec"
]
},
{
"cell_type": "code",
"execution_count": 8,
"metadata": {},
"outputs": [],
"source": [
"if \"pandas\" not in sys.modules:\n",
" print('You have not imported the {} module'.format(\"pandas\"))"
]
},
{
"cell_type": "code",
"execution_count": null,
Expand Down

0 comments on commit 89a5518

Please sign in to comment.