Skip to content

Commit de0bb24

Browse files
committed
pandas-intro: fix MNL example
convert column date_game to type datetime before querying min and max
1 parent 8de42a2 commit de0bb24

File tree

1 file changed

+30
-19
lines changed

1 file changed

+30
-19
lines changed

pandas-intro/pandas_intro.ipynb

Lines changed: 30 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -258,9 +258,18 @@
258258
"metadata": {},
259259
"outputs": [],
260260
"source": [
261-
"nba.loc[nba[\"team_id\"] == \"MNL\", \"date_game\"].min()\n",
261+
"nba[\"date_played\"] = pd.to_datetime(nba[\"date_game\"])"
262+
]
263+
},
264+
{
265+
"cell_type": "code",
266+
"execution_count": null,
267+
"metadata": {},
268+
"outputs": [],
269+
"source": [
270+
"nba.loc[nba[\"team_id\"] == \"MNL\", \"date_played\"].min()\n",
262271
"# Expected:\n",
263-
"# '1/1/1949'"
272+
"# Timestamp('1948-11-04 00:00:00')"
264273
]
265274
},
266275
{
@@ -269,9 +278,9 @@
269278
"metadata": {},
270279
"outputs": [],
271280
"source": [
272-
"nba.loc[nba[\"team_id\"] == \"MNL\", \"date_game\"].max()\n",
281+
"nba.loc[nba[\"team_id\"] == \"MNL\", \"date_played\"].max()\n",
273282
"# Expected:\n",
274-
"# '4/9/1959'"
283+
"# Timestamp('1960-03-26 00:00:00')"
275284
]
276285
},
277286
{
@@ -280,11 +289,11 @@
280289
"metadata": {},
281290
"outputs": [],
282291
"source": [
283-
"nba.loc[nba[\"team_id\"] == \"MNL\", \"date_game\"].agg((\"min\", \"max\"))\n",
292+
"nba.loc[nba[\"team_id\"] == \"MNL\", \"date_played\"].agg((\"min\", \"max\"))\n",
284293
"# Expected:\n",
285-
"# min 1/1/1949\n",
286-
"# max 4/9/1959\n",
287-
"# Name: date_game, dtype: object"
294+
"# min 1948-11-04\n",
295+
"# max 1960-03-26\n",
296+
"# Name: date_played, dtype: datetime64[ns]"
288297
]
289298
},
290299
{
@@ -1541,21 +1550,23 @@
15411550
],
15421551
"metadata": {
15431552
"kernelspec": {
1544-
"argv": [
1545-
"/home/reka/anaconda3/bin/python",
1546-
"-m",
1547-
"ipykernel_launcher",
1548-
"-f",
1549-
"{connection_file}"
1550-
],
15511553
"display_name": "Python 3",
1552-
"env": {},
1553-
"interrupt_mode": "signal",
15541554
"language": "python",
1555-
"metadata": {},
15561555
"name": "python3"
15571556
},
1558-
"language": "python"
1557+
"language": "python",
1558+
"language_info": {
1559+
"codemirror_mode": {
1560+
"name": "ipython",
1561+
"version": 3
1562+
},
1563+
"file_extension": ".py",
1564+
"mimetype": "text/x-python",
1565+
"name": "python",
1566+
"nbconvert_exporter": "python",
1567+
"pygments_lexer": "ipython3",
1568+
"version": "3.9.1"
1569+
}
15591570
},
15601571
"nbformat": 4,
15611572
"nbformat_minor": 2

0 commit comments

Comments
 (0)