@@ -67,31 +67,31 @@ Filtering in SQL is done via a WHERE clause.
6767
6868 .. include :: includes/filtering.rst
6969
70- Just like SQL's OR and AND, multiple conditions can be passed to a DataFrame using | (OR) and &
71- (AND).
70+ Just like SQL's ``OR `` and ``AND ``, multiple conditions can be passed to a DataFrame using ``| ``
71+ (``OR ``) and ``& `` (``AND ``).
72+
73+ Tips of more than $5 at Dinner meals:
7274
7375.. code-block :: sql
7476
75- -- tips of more than $5.00 at Dinner meals
7677 SELECT *
7778 FROM tips
7879 WHERE time = 'Dinner' AND tip > 5.00;
7980
8081 .. ipython :: python
8182
82- # tips of more than $5.00 at Dinner meals
8383 tips[(tips[" time" ] == " Dinner" ) & (tips[" tip" ] > 5.00 )]
8484
85+ Tips by parties of at least 5 diners OR bill total was more than $45:
86+
8587.. code-block :: sql
8688
87- -- tips by parties of at least 5 diners OR bill total was more than $45
8889 SELECT *
8990 FROM tips
9091 WHERE size >= 5 OR total_bill > 45;
9192
9293 .. ipython :: python
9394
94- # tips by parties of at least 5 diners OR bill total was more than $45
9595 tips[(tips[" size" ] >= 5 ) | (tips[" total_bill" ] > 45 )]
9696
9797 NULL checking is done using the :meth: `~pandas.Series.notna ` and :meth: `~pandas.Series.isna `
@@ -132,7 +132,7 @@ Getting items where ``col1`` IS NOT NULL can be done with :meth:`~pandas.Series.
132132
133133 GROUP BY
134134--------
135- In pandas, SQL's GROUP BY operations are performed using the similarly named
135+ In pandas, SQL's `` GROUP BY `` operations are performed using the similarly named
136136:meth: `~pandas.DataFrame.groupby ` method. :meth: `~pandas.DataFrame.groupby ` typically refers to a
137137process where we'd like to split a dataset into groups, apply some function (typically aggregation)
138138, and then combine the groups together.
@@ -160,7 +160,7 @@ The pandas equivalent would be:
160160 Notice that in the pandas code we used :meth: `~pandas.core.groupby.DataFrameGroupBy.size ` and not
161161:meth: `~pandas.core.groupby.DataFrameGroupBy.count `. This is because
162162:meth: `~pandas.core.groupby.DataFrameGroupBy.count ` applies the function to each column, returning
163- the number of ``not null `` records within each.
163+ the number of ``NOT NULL `` records within each.
164164
165165.. ipython :: python
166166
@@ -221,10 +221,10 @@ Grouping by more than one column is done by passing a list of columns to the
221221
222222JOIN
223223----
224- JOINs can be performed with :meth: `~pandas.DataFrame.join ` or :meth: `~pandas.merge `. By default,
225- :meth: `~pandas.DataFrame.join ` will join the DataFrames on their indices. Each method has
226- parameters allowing you to specify the type of join to perform (LEFT, RIGHT, INNER, FULL) or the
227- columns to join on (column names or indices).
224+ `` JOIN `` \s can be performed with :meth: `~pandas.DataFrame.join ` or :meth: `~pandas.merge `. By
225+ default, :meth: `~pandas.DataFrame.join ` will join the DataFrames on their indices. Each method has
226+ parameters allowing you to specify the type of join to perform (`` LEFT ``, `` RIGHT ``, `` INNER ``,
227+ `` FULL ``) or the columns to join on (column names or indices).
228228
229229.. ipython :: python
230230
@@ -233,7 +233,7 @@ columns to join on (column names or indices).
233233
234234 Assume we have two database tables of the same name and structure as our DataFrames.
235235
236- Now let's go over the various types of JOINs .
236+ Now let's go over the various types of `` JOIN `` \s .
237237
238238INNER JOIN
239239~~~~~~~~~~
@@ -259,56 +259,59 @@ column with another DataFrame's index.
259259
260260 LEFT OUTER JOIN
261261~~~~~~~~~~~~~~~
262+
263+ Show all records from ``df1 ``.
264+
262265.. code-block :: sql
263266
264- -- show all records from df1
265267 SELECT *
266268 FROM df1
267269 LEFT OUTER JOIN df2
268270 ON df1.key = df2.key;
269271
270272 .. ipython :: python
271273
272- # show all records from df1
273274 pd.merge(df1, df2, on = " key" , how = " left" )
274275
275276 RIGHT JOIN
276277~~~~~~~~~~
278+
279+ Show all records from ``df2 ``.
280+
277281.. code-block :: sql
278282
279- -- show all records from df2
280283 SELECT *
281284 FROM df1
282285 RIGHT OUTER JOIN df2
283286 ON df1.key = df2.key;
284287
285288 .. ipython :: python
286289
287- # show all records from df2
288290 pd.merge(df1, df2, on = " key" , how = " right" )
289291
290292 FULL JOIN
291293~~~~~~~~~
292- pandas also allows for FULL JOINs, which display both sides of the dataset, whether or not the
293- joined columns find a match. As of writing, FULL JOINs are not supported in all RDBMS (MySQL).
294+ pandas also allows for ``FULL JOIN ``\s , which display both sides of the dataset, whether or not the
295+ joined columns find a match. As of writing, ``FULL JOIN ``\s are not supported in all RDBMS (MySQL).
296+
297+ Show all records from both tables.
294298
295299.. code-block :: sql
296300
297- -- show all records from both tables
298301 SELECT *
299302 FROM df1
300303 FULL OUTER JOIN df2
301304 ON df1.key = df2.key;
302305
303306 .. ipython :: python
304307
305- # show all records from both frames
306308 pd.merge(df1, df2, on = " key" , how = " outer" )
307309
308310
309311 UNION
310312-----
311- UNION ALL can be performed using :meth: `~pandas.concat `.
313+
314+ ``UNION ALL `` can be performed using :meth: `~pandas.concat `.
312315
313316.. ipython :: python
314317
@@ -340,7 +343,7 @@ UNION ALL can be performed using :meth:`~pandas.concat`.
340343
341344 pd.concat([df1, df2])
342345
343- SQL's UNION is similar to UNION ALL, however UNION will remove duplicate rows.
346+ SQL's `` UNION `` is similar to `` UNION ALL `` , however `` UNION `` will remove duplicate rows.
344347
345348.. code-block :: sql
346349
@@ -456,7 +459,7 @@ the same using ``rank(method='first')`` function
456459 Let's find tips with (rank < 3) per gender group for (tips < 2).
457460Notice that when using ``rank(method='min') `` function
458461``rnk_min `` remains the same for the same ``tip ``
459- (as Oracle's RANK() function)
462+ (as Oracle's `` RANK() `` function)
460463
461464.. ipython :: python
462465
@@ -489,7 +492,7 @@ DELETE
489492 DELETE FROM tips
490493 WHERE tip > 9;
491494
492- In pandas we select the rows that should remain, instead of deleting them
495+ In pandas we select the rows that should remain instead of deleting them:
493496
494497.. ipython :: python
495498
0 commit comments