<?xml version='1.0' encoding='UTF-8'?>
<rss xmlns:atom="http://www.w3.org/2005/Atom" xmlns:content="http://purl.org/rss/1.0/modules/content/" version="2.0">
  <channel>
    <title>Let's Discuss the Matter Further</title>
    <link>https://rhodesmill.org/brandon/category/python/feed/</link>
    <description>Thoughts and ideas from Brandon Rhodes</description>
    <atom:link href="https://rhodesmill.org/brandon/category/python/feed/" rel="self"/>
    <docs>http://www.rssboard.org/rss-specification</docs>
    <generator>python-feedgen</generator>
    <language>en</language>
    <lastBuildDate>Fri, 23 Aug 2019 00:00:00 -0400</lastBuildDate>
    <item>
      <title>Animating Ptolemy’s Equant with Python, SVG, and CSS</title>
      <link>https://rhodesmill.org/brandon/2019/animating-the-equant/</link>
      <description>&lt;p&gt;[&lt;strong&gt;UPDATE:&lt;/strong&gt; A full Solar System model is now available that you can view, animated using the techniques described in this post! See &lt;a href="https://rhodesmill.org/ptolemy/"&gt;Ptolemy’s cosmos, to scale&lt;/a&gt;.]&lt;/p&gt;
&lt;p&gt;You will recall
my &lt;a href="https://rhodesmill.org/brandon/2018/matplotlib-blit-repair/"&gt;previous blog post&lt;/a&gt;
that tried to build the necessary scaffolding
for me to finally write up my 2017 PyCon Ireland keynote
on the structure of the Medieval universe.
It ran into several problems with &lt;a href="https://matplotlib.org/3.1.1/api/animation_api.html"&gt;matplotlib animations&lt;/a&gt; —
but, having written that post,
I realized that the problem ran deeper.&lt;/p&gt;
&lt;p&gt;How could &lt;em&gt;any&lt;/em&gt; animation show a Solar System,
when a Solar System’s motion never exactly repeats?
The orbital periods of the planets aren’t exact multiples of each other,
and don’t provide a moment
when the planets reach their original positions
and the animation can start over again.
At whatever moment an animation finished
and looped back to the beginning,
the planets would visibly and jarringly jump back to their original position.&lt;/p&gt;
&lt;p&gt;But then I remembered that modern browsers support animation directly,
and thought:
could a python script produce an SVG diagram
with a separate CSS animation for each planet,
that repeated each time that specific planet finished a revolution?&lt;/p&gt;
&lt;p&gt;The result would be an animated Solar System
that fits into a few thousand bytes,
would render with perfect clarity,
and runs continuously for as long has the viewer was willing to watch!&lt;/p&gt;
&lt;p&gt;But there’s a problem.&lt;/p&gt;
&lt;p&gt;The CSS animation mechanism is perfect
for the simplest possible planetary orbit: uniform circular motion.
Here’s a simple SVG diagram in which a planet
and the line connecting it to the origin
are grouped within a single &lt;code&gt;&amp;lt;g&amp;gt;&lt;/code&gt; element.&lt;/p&gt;

&lt;div class=" highlight hl-python3"&gt;&lt;pre&gt;&lt;span class="o"&gt;%&lt;/span&gt;&lt;span class="n"&gt;pylab&lt;/span&gt; &lt;span class="n"&gt;inline&lt;/span&gt;
&lt;span class="kn"&gt;from&lt;/span&gt; &lt;span class="nn"&gt;IPython.display&lt;/span&gt; &lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="n"&gt;HTML&lt;/span&gt;
&lt;span class="err"&gt;𝜏&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mf"&gt;2.0&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="n"&gt;pi&lt;/span&gt;

&lt;span class="n"&gt;circular_svg&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s"&gt;&amp;#39;&amp;#39;&amp;#39;&lt;/span&gt;
&lt;span class="s"&gt;&amp;lt;svg version=&amp;quot;1.1&amp;quot; width=220 height=220&amp;gt;&lt;/span&gt;
&lt;span class="s"&gt; &amp;lt;g transform=&amp;quot;translate(110, 110)&amp;quot;&amp;gt;&lt;/span&gt;
&lt;span class="s"&gt;  &amp;lt;circle cx=0 cy=0 r=100 stroke=lightgray stroke-width=1 fill=none /&amp;gt;&lt;/span&gt;
&lt;span class="s"&gt;  &amp;lt;g class=&amp;quot;anim %s&amp;quot;&amp;gt;&lt;/span&gt;
&lt;span class="s"&gt;   &amp;lt;line x1=0 y1=0 x2=100 y2=0 stroke=lightgray /&amp;gt;&lt;/span&gt;
&lt;span class="s"&gt;   &amp;lt;circle cx=100 cy=0 r=5 fill=#bb0 /&amp;gt;&lt;/span&gt;
&lt;span class="s"&gt;  &amp;lt;/g&amp;gt;&lt;/span&gt;
&lt;span class="s"&gt;  &amp;lt;circle cx=0 cy=0 r=3 fill=#040 /&amp;gt;&lt;/span&gt;
&lt;span class="s"&gt; &amp;lt;/g&amp;gt;&lt;/span&gt;
&lt;span class="s"&gt;&amp;lt;/svg&amp;gt;&lt;/span&gt;
&lt;span class="s"&gt;&amp;#39;&amp;#39;&amp;#39;&lt;/span&gt;

&lt;span class="n"&gt;HTML&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;circular_svg&lt;/span&gt; &lt;span class="o"&gt;%&lt;/span&gt; &lt;span class="s"&gt;&amp;#39;stationary&amp;#39;&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;pre class="output"&gt;
Populating the interactive namespace from numpy and matplotlib
&lt;/pre&gt;

&lt;div class="output"&gt;
&lt;svg version="1.1" width=220 height=220&gt;
 &lt;g transform="translate(110, 110)"&gt;
  &lt;circle cx=0 cy=0 r=100 stroke=lightgray stroke-width=1 fill=none /&gt;
  &lt;g class="anim stationary"&gt;
   &lt;line x1=0 y1=0 x2=100 y2=0 stroke=lightgray /&gt;
   &lt;circle cx=100 cy=0 r=5 fill=#bb0 /&gt;
  &lt;/g&gt;
  &lt;circle cx=0 cy=0 r=3 fill=#040 /&gt;
 &lt;/g&gt;
&lt;/svg&gt;
&lt;/div&gt;

&lt;p&gt;We use &lt;code&gt;translate()&lt;/code&gt; to move (0,0) to the middle of the diagram
where it can serve as the circle’s center.
We paint a big circle for the orbit,
small circles to mark the orbit’s center and a planet,
and a line to link them.&lt;/p&gt;
&lt;p&gt;&lt;a href="https://rhodesmill.org/brandon/2019/animating-the-equant/"&gt;Read the full article...&lt;/a&gt;&lt;/p&gt;</description>
      <guid isPermaLink="false">https://rhodesmill.org/brandon/2019/animating-the-equant/</guid>
      <pubDate>Fri, 23 Aug 2019 00:00:00 -0400</pubDate>
    </item>
    <item>
      <title>Animating Saturn with matplotlib, a subclass, and mock.patch()</title>
      <link>https://rhodesmill.org/brandon/2018/matplotlib-blit-repair/</link>
      <description>em&gt;Based on my lightning talk at PyOhio 2018&lt;/em&gt;&lt;/p&gt;
&lt;p&gt;I hope that this comes across not as a complaint about matplotlib,
but as a celebration of tools that a dynamic language like Python
offers in situations where a library is seriously misbehaving
and needs some crucial live-edits to run successfully.&lt;/p&gt;
&lt;p&gt;The task had seemed so simple.
To support an upcoming series of posts
based on my 2014 keynote at PyCon Ireland
(“Building the Medieval Universe in 7 Easy Steps with Scientific Python”),
I wanted to render an animation of one of the outer planets —
I chose Saturn —
progressing slowly eastward across the sky
over several seasons and several years.&lt;/p&gt;
&lt;video controls autoplay loop height="648" width="648"&gt;
&lt;source type="video/mp4" src="http://rhodesmill.org/brandon/2018/saturn.mp4"&gt;
&lt;/video&gt;
&lt;p&gt;Instead, I got to spend a weekend wrestling with matplotlib.&lt;/p&gt;
&lt;p&gt;&lt;a href="https://rhodesmill.org/brandon/2018/matplotlib-blit-repair/"&gt;Read the full article...&lt;/a&gt;&lt;/p&gt;</description>
      <guid isPermaLink="false">https://rhodesmill.org/brandon/2018/matplotlib-blit-repair/</guid>
      <pubDate>Sat, 04 Aug 2018 00:00:00 -0400</pubDate>
    </item>
    <item>
      <title>Learning SymPy while eliminating trigonometry from rotations</title>
      <link>https://rhodesmill.org/brandon/2018/sympy/</link>
      <description>&lt;p&gt;I have played with Python’s
&lt;a href="http://docs.sympy.org/latest/index.html"&gt;SymPy symbolic math library&lt;/a&gt; before,
but for the first time last week I used it to solve a real problem!
In the process I had to confront three errors
in my understanding of how SymPy works:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;I had somehow imagined that SymPy was secretly storing
all the equations I was writing
and would use them automatically later.&lt;/li&gt;
&lt;li&gt;I thought I could convince SymPy to eliminate intermediate symbols.&lt;/li&gt;
&lt;li&gt;I thought each variable in my problem needed to be a SymPy symbol.&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;While working through these misunderstandings to a solution,
I ran across two features that made SymPy’s results
easier to use in my Python code than I had expected!&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;SymPy not only supports fancy formatting of math formulae,
but can print them as pure Python expressions
ready to be pasted into a Python program.&lt;/li&gt;
&lt;li&gt;SymPy can perform subexpression elimination
to prevent your code
from computing any sub-result twice.&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;The sections of this post tackle each of the items above in turn.&lt;p&gt;&lt;a href="https://rhodesmill.org/brandon/2018/sympy/"&gt;Read the full article...&lt;/a&gt;&lt;/p&gt;</description>
      <guid isPermaLink="false">https://rhodesmill.org/brandon/2018/sympy/</guid>
      <pubDate>Sat, 16 Jun 2018 00:00:00 -0400</pubDate>
    </item>
    <item>
      <title>Computing a final Tiangong-1 pass with Python</title>
      <link>https://rhodesmill.org/brandon/2018/tiangong/</link>
      <description>&lt;p&gt;Do you remember the thrilling re-entry scene
at the end of the movie &lt;em&gt;Gravity&lt;/em&gt;?
The Chinese space station Tiangong-1
is orbiting at thousands of miles per hour
when (spoiler) it dips fatally into the Earth's upper atmosphere.
The drag buffets and tears at the station’s components
before the increasing friction
finally flashes the air around the station into a glowing plasma,
reducing the station to a shredded sparkling field of debris.&lt;/p&gt;
&lt;p&gt;Well — tomorrow, it’s actually going to happen.&lt;/p&gt;
&lt;p&gt;But before it does, I’d love to see Tiangong-1 from the ground
as it makes its final orbits above our planet.
Can Python help me find a final pass of Tiangong-1
over my town?&lt;/p&gt;
&lt;p&gt;Let’s give it a try!&lt;/p&gt;
&lt;p&gt;&lt;a href="https://rhodesmill.org/brandon/2018/tiangong/"&gt;Read the full article...&lt;/a&gt;&lt;/p&gt;</description>
      <guid isPermaLink="false">https://rhodesmill.org/brandon/2018/tiangong/</guid>
      <pubDate>Sat, 31 Mar 2018 00:00:00 -0400</pubDate>
    </item>
    <item>
      <title>A New Driver for the Original Twiddler</title>
      <link>https://rhodesmill.org/brandon/2018/twiddler/</link>
      <description>
&lt;p&gt;The practical take-away from this post
is that if you’re ever trying to debug serial communications
with a device that — against all tradition —
only transmits when the Data Terminal Ready line is clear
(devices should normally do the opposite:
transmit only when Data Terminal Ready is set),
then never run &lt;tt class="docutils literal"&gt;stty&lt;/tt&gt; on the serial port
to double-check your settings.&lt;/p&gt;
&lt;img alt="The original Twiddler one-handed keyboard" src="http://rhodesmill.org/brandon/2018/twiddler.jpg" /&gt;
&lt;p&gt;Why?&lt;/p&gt;
&lt;p&gt;Because &lt;tt class="docutils literal"&gt;stty&lt;/tt&gt; turns Data Terminal Ready back on.
Without even asking you!&lt;/p&gt;
&lt;p&gt;So the device will never communicate with you,
and you may very nearly conclude that your device is broken
before you happen to remove the &lt;tt class="docutils literal"&gt;stty&lt;/tt&gt; call
and see the device finally work.
So that’s the take-away.
But the full story is a bit longer.&lt;/p&gt;
&lt;p&gt;&lt;a href="https://rhodesmill.org/brandon/2018/twiddler/"&gt;Read the full article...&lt;/a&gt;&lt;/p&gt;</description>
      <guid isPermaLink="false">https://rhodesmill.org/brandon/2018/twiddler/</guid>
      <pubDate>Fri, 30 Mar 2018 00:00:00 -0400</pubDate>
    </item>
    <item>
      <title>Fixing OpenConnect’s VPN Search Domains on Ubuntu</title>
      <link>https://rhodesmill.org/brandon/2017/openconnect-split-dns/</link>
      <description>

&lt;p&gt;A quick technical note about VPN hostnames on Ubuntu Linux,
since otherwise I will forget:&lt;/p&gt;
&lt;p&gt;If other users of your VPN can refer to hosts by an unqualified hostname,
but an Ubuntu user like you receives a &lt;code&gt;not found&lt;/code&gt; error
for the same hostname,
then try creating the following file
(you will need to create the directory by hand).&lt;/p&gt;
&lt;p&gt;&lt;a href="https://rhodesmill.org/brandon/2017/openconnect-split-dns/"&gt;Read the full article...&lt;/a&gt;&lt;/p&gt;</description>
      <guid isPermaLink="false">https://rhodesmill.org/brandon/2017/openconnect-split-dns/</guid>
      <pubDate>Thu, 03 Aug 2017 00:00:00 -0400</pubDate>
    </item>
    <item>
      <title>PyCon Trivia Night, Third Edition</title>
      <link>https://rhodesmill.org/brandon/2016/pycon-trivia-night/</link>
      <description>
&lt;p&gt;At PyCon&amp;nbsp;2016 it was my honor,
for a third year in a row,
to host a Trivia Dinner on the first evening of the conference!
This year’s venue was the storied
&lt;a class="reference external" href="http://www.mcmenamins.com/CrystalBallroom"&gt;Crystal Ballroom&lt;/a&gt;,
a music venue in Downtown Portland’s west end.
To make sure that our event took full advantage of the big stage,
I booked the &lt;a class="reference external" href="http://adcap.biz/"&gt;Adventure Capitalists&lt;/a&gt;,
who followed up the trivia dinner
with a rousing set of punk startup tunes:&lt;/p&gt;
&lt;blockquote class="twitter-tweet" data-lang="en"&gt;&lt;p lang="en" dir="ltr"&gt;Have a conference pass? Come by the Crystal Ballroom and see the Adventure Capitalists! &lt;a href="https://t.co/sg0GxqiDpF"&gt;pic.twitter.com/sg0GxqiDpF&lt;/a&gt;&lt;/p&gt;&amp;mdash; PyCon (@pycon) &lt;a href="https://twitter.com/pycon/status/737502417797799936"&gt;May 31, 2016&lt;/a&gt;&lt;/blockquote&gt;
&lt;script async src="//platform.twitter.com/widgets.js" charset="utf-8"&gt;&lt;/script&gt;&lt;p&gt;Last year’s trivia night questions
focused on such exciting topics as PEP-8 and Python&amp;nbsp;3,
but it turns out that these were fraught topics
about which most of the audience were not very familiar.
So I made a promise:
the PyCon&amp;nbsp;2016 trivia night would be all Python&amp;nbsp;2, all the time!
The questions below dive into and celebrate
the retro roots of the legacy Python language.&lt;/p&gt;
&lt;p&gt;&lt;a href="https://rhodesmill.org/brandon/2016/pycon-trivia-night/"&gt;Read the full article...&lt;/a&gt;&lt;/p&gt;</description>
      <guid isPermaLink="false">https://rhodesmill.org/brandon/2016/pycon-trivia-night/</guid>
      <pubDate>Thu, 09 Jun 2016 00:00:00 -0400</pubDate>
    </item>
    <item>
      <title>PyCon Trivia Night, Second Edition</title>
      <link>https://rhodesmill.org/brandon/2015/pycon-trivia-night/</link>
      <description>
&lt;p&gt;As was the case
during first year that the conference was in Montréal,
I was invited for PyCon&amp;nbsp;2015 to lead an evening dinner trivia contest
on the first full conference day.&lt;/p&gt;
&lt;p&gt;Wanting to help the audience celebrate
all of the advances that are being made in Python&amp;nbsp;3,
I skewed my questions heavily in the direction
of the strides that the core developers are taking
with the new version of the language.
Alas!
My focus was not as popular with the audience
as I had hoped.
It turns out that Python&amp;nbsp;2.7 is still far more popular
than its predecessor,
and many contestants were frustrated
about being asked so many questions and details
about a language hardly anybody used.
So I made a promise to the audience:
if a third trivia dinner happens at PyCon&amp;nbsp;2016 in Portland,
that I will make it Retro Python Trivia Night
and ask all of the questions about the Python&amp;nbsp;2 series!&lt;/p&gt;
&lt;p&gt;The questions follow,
then the answers are way down at the bottom of the post
so you can try answering on your own
before you scroll down and peek.
Enjoy!&lt;/p&gt;
&lt;p&gt;&lt;a href="https://rhodesmill.org/brandon/2015/pycon-trivia-night/"&gt;Read the full article...&lt;/a&gt;&lt;/p&gt;</description>
      <guid isPermaLink="false">https://rhodesmill.org/brandon/2015/pycon-trivia-night/</guid>
      <pubDate>Thu, 16 Apr 2015 00:00:00 -0400</pubDate>
    </item>
    <item>
      <title>The First-Ever PyCon Trivia Night</title>
      <link>https://rhodesmill.org/brandon/2014/pycon-trivia-night/</link>
      <description>&lt;p&gt;PyCon seems to find new ways of fostering community single every year.
&lt;a href="https://us.pycon.org/2014/"&gt;This year’s conference in Montréal&lt;/a&gt;
featured the début
of &lt;a href="https://us.pycon.org/2014/events/dinners/"&gt;official Friday night dinners&lt;/a&gt;
which I first learned about from a surprising email
entitled &lt;code&gt;Want to MC a trivia night at the PyCon dinner?&lt;/code&gt;&lt;/p&gt;
&lt;p&gt;I accepted the invitation!&lt;/p&gt;
&lt;p&gt;While I have enjoyed other volunteer roles at PyCon,
this one was particularly exciting
because of the difference that official evening activities can make
for newcomers.
Remembering my own first conferences,
it can be stressful to face that lonely moment
when the evening lightning talks have just finished.
Everyone else seems to pair up and make dinner plans so quickly.
Unless you can somehow involve yourself in someone else’s dinner plans,
you picture a long walk back to your hotel
to order room service — alone —
while everyone else sits at candlelit tables in real restaurants
talking and laughing and enjoying Québécois cuisine.
I hope that my dinner, plus the one hosted by Greg Brockman,
provided a few people with a safe default option
who otherwise might have had to fend for themselves.
&lt;p&gt;&lt;a href="https://rhodesmill.org/brandon/2014/pycon-trivia-night/"&gt;Read the full article...&lt;/a&gt;&lt;/p&gt;</description>
      <guid isPermaLink="false">https://rhodesmill.org/brandon/2014/pycon-trivia-night/</guid>
      <pubDate>Tue, 29 Apr 2014 00:00:00 -0400</pubDate>
    </item>
    <item>
      <title>Learning Pandas through payroll taxes and paystubs</title>
      <link>https://rhodesmill.org/brandon/2014/pandas-payroll/</link>
      <description>&lt;p&gt;I will admit it:
I only thought to pull out &lt;a href="http://pandas.pydata.org/"&gt;Pandas&lt;/a&gt;
when my Python script was nearly complete,
because running &lt;code&gt;print&lt;/code&gt; on a Pandas data frame
would save me the trouble of formatting 12 rows of data by hand.&lt;/p&gt;
&lt;p&gt;But as I added the &lt;code&gt;import&lt;/code&gt; statement,
it suddenly struck me
that Pandas aggregate operations
might be able to replace some of the steps inside my big &lt;code&gt;for&lt;/code&gt; loop.
Half an hour later,
my loop had disappeared completely
and my entire script was reduced
to a short sequence of Pandas method calls!&lt;/p&gt;
&lt;p&gt;This post is a brief tour of the final script,
written up as &lt;a href="http://rhodesmill.org/brandon/2014/pandas-payroll.ipynb"&gt;an IPython notebook&lt;/a&gt;
and organized around five basic lessons
that I learned about Pandas by applying it to this problem.&lt;/p&gt;
&lt;h2 id="1.-Pandas-lets-you-bring-your-own-objects"&gt;1. Pandas lets you bring your own objects&lt;a class="anchor-link" href="#1.-Pandas-lets-you-bring-your-own-objects"&gt;&amp;#182;&lt;/a&gt;&lt;/h2&gt;&lt;p&gt;The most surprising feature
of tools like the NumPy vector library and the Pandas data series
might be that they let you bring your own objects to the party.&lt;/p&gt;
&lt;p&gt;Since they were invented to efficiently pack
millions of floating-point values into a single Python object,
you might think that these libraries would only work
with numeric types that they themselves can express as vectors.
But in fact they have a clean fallback behavior
when faced with alternative numeric types:
they essentially turn into Python lists,
and keep a separate reference to each object that you have supplied.
When asked to perform their famous aggregate operations —
this is the crucial step —
they simply turn to the objects
and call the &lt;code&gt;__add__()&lt;/code&gt; or &lt;code&gt;__mul__()&lt;/code&gt; method of every single item
to build the result.&lt;/p&gt;
&lt;p&gt;When doing taxes and pay stubs
we always want to use Python &lt;code&gt;Decimal&lt;/code&gt; objects
to guarantee correctness and careful rounding to cents,
which we can implement with a simple &lt;code&gt;c()&lt;/code&gt; function:&lt;/p&gt;

&lt;div class=" highlight hl-python3"&gt;&lt;pre&gt;&lt;span class="kn"&gt;from&lt;/span&gt; &lt;span class="nn"&gt;decimal&lt;/span&gt; &lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="n"&gt;Decimal&lt;/span&gt;

&lt;span class="n"&gt;one_cent&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;Decimal&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;&amp;#39;0.01&amp;#39;&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;c&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;value&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
    &lt;span class="s"&gt;&amp;quot;Convert `value` to Decimal cents.&amp;quot;&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;Decimal&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;value&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;quantize&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;one_cent&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;You might think that my next step
will be building a twelve-element list
with which to initialize the monthly wages
in our payroll table.
But data frames let us do something simpler:
we can supply a single value for a column,
and Pandas will automatically broadcast it
across the whole index that we have defined.
Here we set up the twelve calendar months of the year
and imagine the simple case
of someone who makes the same wage every month:&lt;/p&gt;

&lt;div class=" highlight hl-python3"&gt;&lt;pre&gt;&lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="nn"&gt;pandas&lt;/span&gt; &lt;span class="k"&gt;as&lt;/span&gt; &lt;span class="nn"&gt;pd&lt;/span&gt;
&lt;span class="kn"&gt;from&lt;/span&gt; &lt;span class="nn"&gt;calendar&lt;/span&gt; &lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="n"&gt;month_abbr&lt;/span&gt;

&lt;span class="n"&gt;df&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;pd&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;DataFrame&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;index&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="n"&gt;month_abbr&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;:])&lt;/span&gt;
&lt;span class="n"&gt;df&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s"&gt;&amp;#39;wage&amp;#39;&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;c&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;&amp;#39;11000.00&amp;#39;&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="nb"&gt;print&lt;/span&gt; &lt;span class="n"&gt;df&lt;/span&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;pre class="output"&gt;
         wage
Jan  11000.00
Feb  11000.00
Mar  11000.00
Apr  11000.00
May  11000.00
Jun  11000.00
Jul  11000.00
Aug  11000.00
Sep  11000.00
Oct  11000.00
Nov  11000.00
Dec  11000.00
&lt;/pre&gt;
&lt;p&gt;An example wage of $11,000 per month might sound grandiose,
but I have chosen it so that this example
will reach the Social Security wage limit by the end of the year —
to test whether we model the limit correctly in our data frame.&lt;/p&gt;
&lt;h2 id="2.-Mapping-is-suddenly-worth-it"&gt;2. Mapping is suddenly worth it&lt;a class="anchor-link" href="#2.-Mapping-is-suddenly-worth-it"&gt;&amp;#182;&lt;/a&gt;&lt;/h2&gt;&lt;p&gt;The second surprise of working with Pandas
is the convenience of its &lt;code&gt;map()&lt;/code&gt; method,
&lt;p&gt;&lt;a href="https://rhodesmill.org/brandon/2014/pandas-payroll/"&gt;Read the full article...&lt;/a&gt;&lt;/p&gt;</description>
      <guid isPermaLink="false">https://rhodesmill.org/brandon/2014/pandas-payroll/</guid>
      <pubDate>Fri, 14 Feb 2014 00:00:00 -0500</pubDate>
    </item>
  </channel>
</rss>
