<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: josh friedlander</title>
    <description>The latest articles on DEV Community by josh friedlander (@oshkoshbgoshjos).</description>
    <link>https://dev.to/oshkoshbgoshjos</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F169626%2F5315af3d-554b-476f-ae77-ac1438d204c0.jpeg</url>
      <title>DEV Community: josh friedlander</title>
      <link>https://dev.to/oshkoshbgoshjos</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/oshkoshbgoshjos"/>
    <language>en</language>
    <item>
      <title>4 Easy Pieces</title>
      <dc:creator>josh friedlander</dc:creator>
      <pubDate>Mon, 20 May 2019 16:04:14 +0000</pubDate>
      <link>https://dev.to/oshkoshbgoshjos/4-easy-pieces-3bk2</link>
      <guid>https://dev.to/oshkoshbgoshjos/4-easy-pieces-3bk2</guid>
      <description>&lt;p&gt;Here are some minor hacks to improve your experience with Pandas and Jupyter Notebook. Jupyter Notebooks are incredible tools; Donald Knuth spent years unsuccessfully trying to make literate programming a thing, but this might finally be the form in which it takes off.&lt;/p&gt;

&lt;p&gt;(By the way, you may think that this post is named after the "Feynman Lectures for Dummies" book &lt;a href="https://www.goodreads.com/book/show/5553.Six_Easy_Pieces"&gt;Six Easy Pieces&lt;/a&gt;, but in fact that book probably referenced the 1970 film &lt;em&gt;Five Easy Pieces&lt;/em&gt;, to which this post serves as a prequel in title, though not in substance.)&lt;/p&gt;

&lt;h4&gt;
  
  
  0
&lt;/h4&gt;

&lt;p&gt;I usually start off my notebooks, after the usual import statements, with:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;pd.options.display.max_rows = 999
pd.options.display.max_columns = 99
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;It's often convenient to be able to see a whole df, or a big chunk of it, while working with it. Also, if your notebook is getting out of hand because you always use the same Untitled7.ipynb (who among us has not etc.), consider using the &lt;a href="https://jupyter-contrib-nbextensions.readthedocs.io/en/latest/nbextensions/codefolding/readme.html"&gt;Codefolding extension in nbextensions&lt;/a&gt; so you can hide away all the old code you swear you might need someday.&lt;/p&gt;

&lt;h4&gt;
  
  
  1
&lt;/h4&gt;

&lt;p&gt;If you've run a calculation in a Jupyter notebook but forgot to assign it, Jupyter's got your back. In the next cell you can assign it as  &lt;code&gt;_&lt;/code&gt;.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;[1] long_calculation.solve() 
# Aaaah, no!
[2] result = _
# Phew
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;h4&gt;
  
  
  2
&lt;/h4&gt;

&lt;p&gt;Ben Lindsay &lt;a href="https://twitter.com/ben_j_lindsay/status/1108427124518645762"&gt;says&lt;/a&gt; &lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;One of the most underrated &lt;a href="https://twitter.com/hashtag/Pandas?src=hash"&gt;#&lt;strong&gt;Pandas&lt;/strong&gt;&lt;/a&gt; functions in &lt;a href="https://twitter.com/hashtag/Python?src=hash"&gt;#&lt;strong&gt;Python&lt;/strong&gt;&lt;/a&gt; is &lt;code&gt;.query()&lt;/code&gt;. I use it all the time.&lt;br&gt;
data = data.query('age==42')&lt;br&gt;
looks so much nicer than:&lt;br&gt;
data = data[data['age'] == 42]&lt;br&gt;
And it allows chaining like:&lt;br&gt;
data = data.query('age &amp;gt;18').query('age &amp;lt; 32')&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;I tend to agree. I like brevity, although it's hard to get over how grotesquely unpythonic it looks (even by the already low standards of Pandas). &lt;/p&gt;

&lt;h4&gt;
  
  
  2.5
&lt;/h4&gt;

&lt;p&gt;Lastly: you can't do chained comparison in Pandas &lt;code&gt;(18 &amp;lt; df.age &amp;lt; 60 )&lt;/code&gt; but a &lt;a href="(https://stackoverflow.com/a/18091240)"&gt;Stack Overflow rando&lt;/a&gt; points out that you sort-of can like this&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;df['18 &amp;lt;= age &amp;lt;= 60']
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;or with the abovementioned &lt;code&gt;query&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;df.query('18 &amp;lt;= age &amp;lt;= 60')
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;It all goes through some kind of &lt;code&gt;eval&lt;/code&gt;-like lexical parsing, which is generally &lt;a href="https://nedbatchelder.com/blog/201206/eval_really_is_dangerous.html"&gt;not a good idea in Python&lt;/a&gt;. Yeah I know, I don't like it either.&lt;/p&gt;

&lt;p&gt;Happy data scienc-ing.&lt;/p&gt;

</description>
      <category>python</category>
      <category>pandas</category>
      <category>jupyter</category>
    </item>
  </channel>
</rss>
