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
into other cells to compute them for other columns. In pandas, you're able to do operations on whole
147
+
columns directly.
148
+
149
+
.. include:: includes/column_operations.rst
150
+
151
+
Note that we aren't having to tell it to do that subtraction cell-by-cell — pandas handles that for
152
+
us. See :ref:`how to create new columns derived from existing columns <10min_tut_05_columns>`.
153
+
154
+
155
+
Filtering
156
+
~~~~~~~~~
157
+
158
+
`In Excel, filtering is done through a graphical menu. <https://support.microsoft.com/en-us/office/filter-data-in-a-range-or-table-01832226-31b5-4568-8806-38c37dcc180e>`_
159
+
160
+
.. image:: ../../_static/excel_filter.png
161
+
:alt:Screenshot showing filtering of the total_bill column to values greater than 10
162
+
:align:center
163
+
164
+
.. include:: includes/filtering.rst
165
+
166
+
If/then logic
167
+
~~~~~~~~~~~~~
168
+
169
+
Let's say we want to make a ``bucket`` column with values of ``low`` and ``high``, based on whether
170
+
the ``total_bill`` is less or more than $10.
171
+
172
+
In spreadsheets, logical comparison can be done with `conditional formulas
- `Referencing a range <https://support.microsoft.com/en-us/office/create-or-change-a-cell-reference-c7b8b95d-c594-4488-947e-c835903cebaa>`_ from one worksheet into another
236
+
237
+
Since spreadsheet columns are typically `named in a header row
renaming a column is simply a matter of changing the text in that first cell.
240
+
241
+
.. include:: includes/column_selection.rst
242
+
243
+
244
+
Sorting by values
245
+
~~~~~~~~~~~~~~~~~
246
+
247
+
Sorting in spreadsheets is accomplished via `the sort dialog <https://support.microsoft.com/en-us/office/sort-data-in-a-range-or-table-62d0b95d-2a90-4610-a6ae-2e545c4a4654>`_.
248
+
249
+
.. image:: ../../_static/excel_sort.png
250
+
:alt:Screenshot dialog from Excel showing sorting by the sex then total_bill columns
251
+
:align:center
252
+
253
+
.. include:: includes/sorting.rst
254
+
255
+
Other considerations
256
+
--------------------
138
257
139
258
Fill Handle
140
259
~~~~~~~~~~~
@@ -157,21 +276,6 @@ This can be achieved by creating a series and assigning it to the desired cells.
157
276
158
277
df
159
278
160
-
Filters
161
-
~~~~~~~
162
-
163
-
Filters can be achieved by using slicing.
164
-
165
-
The examples filter by 0 on column AAA, and also show how to filter by multiple
166
-
values.
167
-
168
-
.. ipython:: python
169
-
170
-
df[df.AAA==0]
171
-
172
-
df[(df.AAA==0) | (df.AAA==2)]
173
-
174
-
175
279
Drop Duplicates
176
280
~~~~~~~~~~~~~~~
177
281
@@ -192,7 +296,6 @@ This is supported in pandas via :meth:`~DataFrame.drop_duplicates`.
192
296
193
297
df.drop_duplicates(["class", "student_count"])
194
298
195
-
196
299
Pivot Tables
197
300
~~~~~~~~~~~~
198
301
@@ -203,6 +306,7 @@ let's find the average gratuity by size of the party and sex of the server.
203
306
In Excel, we use the following configuration for the PivotTable:
204
307
205
308
.. image:: ../../_static/excel_pivot.png
309
+
:alt:Screenshot showing a PivotTable in Excel, using sex as the column, size as the rows, then average tip as the values
In spreadsheets, `formulas <https://support.microsoft.com/en-us/office/overview-of-formulas-in-excel-ecfdc708-9162-49e8-b993-c311f47ca173>`_
220
-
are often created in individual cells and then `dragged <https://support.microsoft.com/en-us/office/copy-a-formula-by-dragging-the-fill-handle-in-excel-for-mac-dd928259-622b-473f-9a33-83aa1a63e218>`_
221
-
into other cells to compute them for other columns. In pandas, you'll be doing more operations on
222
-
full columns.
223
-
224
-
As an example, let's create a new column "girls_count" and try to compute the number of boys in
0 commit comments