Skip to content

Commit afea4de

Browse files
committed
Add explanation of how to connect to MySQL / Postgres
1 parent a2eaaa0 commit afea4de

File tree

2 files changed

+44
-1
lines changed

2 files changed

+44
-1
lines changed

cookbook/Chapter 4 - Find out on which weekday people bike the most with groupby and aggregate.ipynb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -590,7 +590,7 @@
590590
"source": [
591591
"Let's put all that together, to prove how easy it is. 6 lines of magical pandas!\n",
592592
"\n",
593-
"If you want to play around, try changing `sum` to `max`, `np.median`, or any other function you like."
593+
"If you want to play around, try changing `sum` to `max`, `numpy.median`, or any other function you like."
594594
]
595595
},
596596
{

cookbook/Chapter 9 - Loading data from SQL databases.ipynb

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -456,6 +456,49 @@
456456
"`pd.read_sql(\"SELECT whatever from your_table\", con)`"
457457
]
458458
},
459+
{
460+
"cell_type": "markdown",
461+
"metadata": {},
462+
"source": [
463+
"# 9.3 Connecting to other kinds of database"
464+
]
465+
},
466+
{
467+
"cell_type": "markdown",
468+
"metadata": {},
469+
"source": [
470+
"To connect to a MySQL database:"
471+
]
472+
},
473+
{
474+
"cell_type": "code",
475+
"collapsed": false,
476+
"input": [
477+
"import MySQLdb\n",
478+
"con = MySQLdb.connect(host=\"localhost\", db=\"test\")"
479+
],
480+
"language": "python",
481+
"metadata": {},
482+
"outputs": []
483+
},
484+
{
485+
"cell_type": "markdown",
486+
"metadata": {},
487+
"source": [
488+
"To connect to a PostgreSQL database:"
489+
]
490+
},
491+
{
492+
"cell_type": "code",
493+
"collapsed": false,
494+
"input": [
495+
"import psycopg2\n",
496+
"con = psycopg2.connect(host=\"localhost\")"
497+
],
498+
"language": "python",
499+
"metadata": {},
500+
"outputs": []
501+
},
459502
{
460503
"cell_type": "markdown",
461504
"metadata": {},

0 commit comments

Comments
 (0)