Skip to content

Commit b522014

Browse files
committed
DOC: improve formula documentation under Getting Started
- Mention apply() in documentation around deriving columns - Simplify code for doing column subtraction in Excel doc
1 parent 22f9f4f commit b522014

File tree

2 files changed

+14
-11
lines changed

2 files changed

+14
-11
lines changed

doc/source/getting_started/comparison/comparison_with_excel.rst

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -128,25 +128,26 @@ This can be achieved by using ``pandas.pivot_table`` for examples and reference,
128128
please see `pandas.pivot_table <http://pandas.pydata.org/pandas-docs/stable/generated/pandas.pivot_table.html>`__
129129

130130

131-
Formulae
131+
Formulas
132132
~~~~~~~~
133133

134-
Let's create a new column "girls_count" and try to compute the number of boys in
134+
In spreadsheets, `formulas <https://support.microsoft.com/en-us/office/overview-of-formulas-in-excel-ecfdc708-9162-49e8-b993-c311f47ca173>`_
135+
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>`_
136+
into other cells to compute them for other columns. In pandas, you'll be doing more operations on
137+
full columns.
138+
139+
As an example, let's create a new column "girls_count" and try to compute the number of boys in
135140
each class.
136141

137142
.. ipython:: python
138143
139144
df["girls_count"] = [21, 12, 21, 31, 23, 17]
140145
df
141-
142-
143-
def get_count(row):
144-
return row["student_count"] - row["girls_count"]
145-
146-
147-
df["boys_count"] = df.apply(get_count, axis=1)
146+
df["boys_count"] = df["student_count"] - df["girls_count"]
148147
df
149148
149+
Note that we aren't having to tell it to do that subtraction cell-by-cell — pandas handles that for
150+
us. See :ref:`10min_tut_05_columns` for more information.
150151

151152
VLOOKUP
152153
~~~~~~~

doc/source/getting_started/intro_tutorials/05_add_columns.rst

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -107,11 +107,13 @@ values in each row*.
107107
</li>
108108
</ul>
109109

110-
Also other mathematical operators (+, -, \*, /) or
111-
logical operators (<, >, =,…) work element wise. The latter was already
110+
Also other mathematical operators (``+``, ``-``, ``\*``, ``/``) or
111+
logical operators (``<``, ``>``, ``=``,…) work element wise. The latter was already
112112
used in the :ref:`subset data tutorial <10min_tut_03_subset>` to filter
113113
rows of a table using a conditional expression.
114114

115+
If you need more advanced logic, you can use arbitrary Python code via :meth:`~DataFrame.apply`.
116+
115117
.. raw:: html
116118

117119
<ul class="task-bullet">

0 commit comments

Comments
 (0)