<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Ted Petrou on Medium]]></title>
        <description><![CDATA[Stories by Ted Petrou on Medium]]></description>
        <link>https://medium.com/@petrou-theodore?source=rss-cf7f60f2eeb3------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/2*0H9qOvDgUXs0KFICewpniQ.png</url>
            <title>Stories by Ted Petrou on Medium</title>
            <link>https://medium.com/@petrou-theodore?source=rss-cf7f60f2eeb3------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sat, 14 Nov 2026 02:47:55 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@petrou-theodore/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Convert Trapped Tables within PDFs to Pandas DataFrames]]></title>
            <link>https://medium.com/dunder-data/convert-trapped-tables-within-pdfs-to-pandas-dataframes-b5c4c7ac00f9?source=rss-cf7f60f2eeb3------2</link>
            <guid isPermaLink="false">https://medium.com/p/b5c4c7ac00f9</guid>
            <category><![CDATA[tabula]]></category>
            <category><![CDATA[python]]></category>
            <category><![CDATA[pdf]]></category>
            <category><![CDATA[pandas]]></category>
            <category><![CDATA[data-science]]></category>
            <dc:creator><![CDATA[Ted Petrou]]></dc:creator>
            <pubDate>Thu, 01 Dec 2022 14:37:41 GMT</pubDate>
            <atom:updated>2022-12-01T15:15:54.967Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Z4Ar9RwJNOxPhMXg4aSC8w.png" /></figure><p>Pandas is the most popular Python data analysis library available today and can read in data directly from a wide variety of sources, including CSVs, Excel Workbooks, JSON files, SQL databases, parquet files, and even from your clipboard. Currently, there is no direct method using pandas to read in data trapped within a PDF file. Thankfully, the <a href="https://tabula-py.readthedocs.io/en/latest/index.html">tabula-py library</a> is available to read in these tables within a PDF as pandas DataFrames.</p><p>The tabula-py library itself is a wrapper around <a href="https://github.com/tabulapdf/tabula-java">tabula-java</a>, a command line tool for extracting trapped data within a PDF. <a href="https://tabula-py.readthedocs.io/en/latest/getting_started.html">Get started</a> by installing it with pip install tabula-py.</p><h4>Sample PDF — Book Sales</h4><p>For this tutorial, we will extract a single table within the royalty statement from <a href="https://www.amazon.com/Pandas-Cookbook-Scientific-Computing-Visualization/dp/1784393878">Pandas Cookbook</a>, a book I published in 2017. An image of the PDF is displayed below.</p><figure><img alt="" src="https://cdn-images-1.medium.com/proxy/1*oaLWzl1CyjAcpmX9ilHwCw.png" /></figure><h4>Automatic table detection</h4><p>Tabula-py automatically detects all tables on the pages provided with its read_pdf function. All we have to do is provide it the file path of the PDF document and the pages to extract. The returned result is a list of DataFrames, stored here as the variable dfs.</p><pre>import pandas as pd<br>import tabula<br>dfs = tabula.read_pdf(&#39;2018Q1.pdf&#39;, pages=1)<br>len(dfs)</pre><pre>1</pre><p>Tabula has detected a single table. Let’s output the DataFrame to see how well the extraction worked.</p><pre>df = dfs[0]<br>df</pre><figure><img alt="png" src="https://cdn-images-1.medium.com/proxy/1*yZDtLPsyFu_P4CB1LTy8JA.png" /></figure><p>For this PDF, I wanted to extract the table beginning in the middle box with the four columns <strong>Format</strong>, <strong>Copies</strong>, <strong>Revenue</strong>, <strong>Royalties</strong>. Instead, Tabula extracted the two boxes above this and returned a three-column table combining Copies and Revenue. While the result isn’t bad, it’s not usable in the current form. We could use pandas at this point to clean up the data, but tabula-py provides us parameters to define the boundary of the entire table itself and the positioning of the columns.</p><p>The relative_area and relative_columns parameters are set to True which allows us to provide boundaries to both the area and columns parameters as a percentage of the page, as opposed to point coordinates. In my opinion, it is easier to define a boundary using relative page percentage.</p><p>The area column is passed a four-item list of top, left, bottom, and right. These represent the boundaries of the table relative to the page. The three-item list for columns represent the vertical lines separating the four columns. Let&#39;s re-read in the data and output the resulting DataFrame.</p><pre>dfs = tabula.read_pdf(&#39;2018Q1.pdf&#39;, pages=1, <br>                      relative_area=True,<br>                      relative_columns=True,<br>                      area=[42, 0, 60, 100], <br>                      columns= [45, 65, 82])<br>df = dfs[0]<br>df</pre><figure><img alt="png" src="https://cdn-images-1.medium.com/proxy/1*GOlPqeJNhSijk8WkLgRusg.png" /></figure><h4>Convert to numeric</h4><p>This extraction looks much better and almost exactly what we want. Let’s check the data types of each column to understand which ones need more processing.</p><pre>df.dtypes</pre><pre>Format       object<br>Copies        int64<br>Revenue      object<br>Royalties    object<br>dtype: object</pre><p>Conveniently, the Copies column was successfully converted to an integer. The Revenue and Royalties columns were read in as strings. We’ll now have to turn to pandas to convert these columns to floats. We do so by replacing any dollar signs, commas, and spaces with empty spaces using a regular expression.</p><pre>df[[&#39;Revenue&#39;, &#39;Royalties&#39;]] = (df[[&#39;Revenue&#39;, &#39;Royalties&#39;]]<br>                                  .replace(&#39;[$, ]&#39;, &#39;&#39;, regex=True)<br>                                  .astype(&#39;float64&#39;))<br>df</pre><figure><img alt="png" src="https://cdn-images-1.medium.com/proxy/1*NN0qDgENUPOjMlDycJ2Byg.png" /></figure><h4>Summary</h4><p>In this tutorial, we passed custom inputs into tabula-py’s read_pdf function to extract a table trapped within a PDF as a pandas DataFrame. We then cleaned up the result with pandas ability to replace characters using a regular expression. Several <a href="https://tabula-py.readthedocs.io/en/latest/index.html">more options</a> are available to tabula-py to customize the extraction process.</p><h3>Master Data Analysis with Python</h3><p>If you enjoyed this lesson and are looking to become an expert with Pandas, then check out my book, <a href="https://tabula-py.readthedocs.io/en/latest/index.html">Master Data Analysis with Python</a>. It is the most comprehensive Pandas book available, and comes with video lessons, 500+ exercises with solutions, and certification exams.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=b5c4c7ac00f9" width="1" height="1" alt=""><hr><p><a href="https://medium.com/dunder-data/convert-trapped-tables-within-pdfs-to-pandas-dataframes-b5c4c7ac00f9">Convert Trapped Tables within PDFs to Pandas DataFrames</a> was originally published in <a href="https://medium.com/dunder-data">Dunder Data</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Learning Slowly is Faster than Learning Fast]]></title>
            <link>https://petrou-theodore.medium.com/learning-slowly-is-faster-than-learning-fast-31a0c4146a95?source=rss-cf7f60f2eeb3------2</link>
            <guid isPermaLink="false">https://medium.com/p/31a0c4146a95</guid>
            <category><![CDATA[python]]></category>
            <category><![CDATA[data-science]]></category>
            <category><![CDATA[learning]]></category>
            <dc:creator><![CDATA[Ted Petrou]]></dc:creator>
            <pubDate>Tue, 29 Nov 2022 13:25:45 GMT</pubDate>
            <atom:updated>2022-11-29T13:25:45.312Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*mfFx5BSv2IMbrqca" /></figure><p>Lots of courses promise to teach you X or turn you into Y within Z weeks. This <strong>learning as fast as possible</strong> approach may indeed cover lots of material with you producing interesting final products. You will feel a sense of accomplishment that you’ve quickly reached certain milestones towards X/Y.</p><p>In all likelihood, you’ve skipped over certain areas of development in order to reach some final stage. You may find it harder to progress from this point because you’ve taken a narrow path without a complete understanding of the fundamentals. When you enter the real-world, projects demand deep knowledge of a wide array of skills.</p><p>You many have to go back and cover these fundamentals that were originally ignored. This might lead you to frustration because you’ll be producing far less interesting results than what was covered in the original course.</p><p>This is why I highly recommend a slow approach where material is covered thoroughly without knowledge gaps. Skills are built incrementally, one small step at a time. It will be tempting to reach up high to that shiny project that others are sharing on social media, but you may find yourself falling without that firm understanding of the fundamentals.</p><p>All of the courses I teach use this <strong>slow, thorough approach without knowledge gaps</strong>, where skills are built incrementally. Yes, they may be boring at times, but if your goal is to have deep knowledge in a professional setting then I believe this path is effective.</p><p>And as a bonus, I believe this path to be <strong>faster in the long run</strong> as the knowledge you gain will be retained easier and for a longer period of time compared to skipping around to final results.</p><h4>True for other learning pursuits</h4><p>I believe this approach is also best for other learning pursuits — whether it is a new language, playing an instrument, a sport, etc… learning slowly, and thoroughly without knowledge gaps is best.</p><h3>Comprehensive Python Data Science Courses</h3><p>Immerse yourself in my comprehensive path for mastering data science with Python. <a href="https://www.dunderdata.com/all-access-pass"><strong>Purchase the All Access Pass to get lifetime access to all current and future courses</strong></a><strong>.</strong> Some of the courses it contains:</p><ul><li><a href="https://www.dunderdata.com/master-the-fundamentals-of-python"><strong>Master the Fundamentals of Python</strong> </a>— A comprehensive introduction to Python (300+ pages, 150+ exercises, 25 hours of video)</li><li><a href="https://www.dunderdata.com/master-data-analysis-with-python"><strong>Master Data Analysis with Python</strong> </a>— The most comprehensive course available to learn pandas. (800+ pages and 500+ exercises, 10 hours of video)</li></ul><p><a href="https://www.dunderdata.com/all-access-pass"><strong>Get the All Access Pass now!</strong></a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=31a0c4146a95" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Use the Pandas String-Only get_dummies Method to Instantly Restructure your Data]]></title>
            <link>https://medium.com/dunder-data/use-the-pandas-string-only-get-dummies-method-to-instantly-restructure-your-data-735e499a45a9?source=rss-cf7f60f2eeb3------2</link>
            <guid isPermaLink="false">https://medium.com/p/735e499a45a9</guid>
            <category><![CDATA[python]]></category>
            <category><![CDATA[pandas]]></category>
            <category><![CDATA[data-analysis]]></category>
            <category><![CDATA[data-science]]></category>
            <dc:creator><![CDATA[Ted Petrou]]></dc:creator>
            <pubDate>Mon, 24 Oct 2022 19:33:21 GMT</pubDate>
            <atom:updated>2022-11-30T16:28:36.705Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*UGmCTNw5Kr70IoJ-rrArvQ.png" /></figure><p>In this post, you’ll learn how to use the fantastic str.get_dummies Pandas Series method to instantly restructure trapped data within a string. We begin by reading in a small sample dataset containing people&#39;s favorite fruits.</p><pre>import pandas as pd<br>df = pd.read_csv(&#39;data/fruits.csv&#39;)<br>df</pre><figure><img alt="png" src="https://cdn-images-1.medium.com/proxy/1*6f7tEwiVKeqfd2lgkeDPPg.png" /></figure><p>Notice that the fruit column has multiple fruit names in each cell separated by a pipe character. While this format compactly represents the data, it isn’t the most suitable for answering basic questions such as:</p><ul><li>What is the number of fruit per person?</li><li>How many people enjoy banana?</li><li>Which people enjoy both oranges and bananas?</li><li>How any fruits are in-common with each person?</li></ul><h4>Attempt to answer questions in current form</h4><p>It’s possible to answer these questions in the current format using Pandas, though, we will see how these ways are sub-optimal. Here we find the number of fruit per person by adding one to the count of the pipe characters.</p><pre>s = df.set_index(&#39;name&#39;)[&#39;fruits&#39;]<br>s.str.count(r&#39;\|&#39;) + 1</pre><pre>name<br>Ana        5<br>Bill       2<br>Calvin     2<br>Dean       2<br>Elias      3<br>Felicia    2<br>George     5<br>Henry      2<br>Name: fruits, dtype: int64</pre><p>The number of people who enjoy banana.</p><pre>s.str.contains(&#39;banana&#39;).sum()</pre><pre>3</pre><p>The people that enjoy both oranges and banana.</p><pre>s.str.contains(&#39;(?=.*orange)(?=.*banana)&#39;)</pre><pre>name<br>Ana         True<br>Bill       False<br>Calvin     False<br>Dean       False<br>Elias      False<br>Felicia    False<br>George      True<br>Henry       True<br>Name: fruits, dtype: bool</pre><p>Finding the number of fruits in-common with both people is particularly difficult and is a clear case for reformatting the data.</p><h4>Better formatting of the data</h4><p>All of these questions can be bettered answered if the data is in a different format. The get_dummies string-only method will split all values in a single cell into their own columns creating 0/1 indicator variables. Here, we pass in the pipe character to get_dummies, producing the following DataFrame.</p><pre>df1 = s.str.get_dummies(&#39;|&#39;)<br>df1</pre><figure><img alt="png" src="https://cdn-images-1.medium.com/proxy/1*6mErkbCrJcqLNa6FRZrXuQ.png" /></figure><p>We can now answer the same questions as before. Here, we count the number of fruit for each person.</p><pre>df1.sum(axis=1)</pre><pre>name<br>Ana        5<br>Bill       2<br>Calvin     2<br>Dean       2<br>Elias      3<br>Felicia    2<br>George     5<br>Henry      2<br>dtype: int64</pre><p>We sum up a single column to count the total number of people who enjoy bananas.</p><pre>df1[&#39;banana&#39;].sum()</pre><pre>3</pre><p>Here, we use the query method to select each person who likes both oranges and bananas.</p><pre>df1.query(&#39;orange + banana == 2&#39;)</pre><figure><img alt="png" src="https://cdn-images-1.medium.com/proxy/1*buX4VZgw2TsXAe-33NKCmw.png" /></figure><p>Finding the number of fruits in-common with each person is where the largest gain from restructuring comes from. Here, we use the matrix multiplication operator to multiply the DataFrame to itself.</p><pre>df1 @ df1.T</pre><figure><img alt="png" src="https://cdn-images-1.medium.com/proxy/1*DOwPP3kkQaPZOoiVcU3gmw.png" /></figure><h4>Master Data Analysis with Python</h4><p>If you enjoyed this tip and are looking to become an expert with Pandas, then check out my extremely comprehensive book, <a href="https://dunderdata.com/master-data-analysis-with-python">Master Data Analysis with Python</a>. It is the most comprehensive Pandas book available, comes with 500+ exercises, video tutorials, and certification exams.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=735e499a45a9" width="1" height="1" alt=""><hr><p><a href="https://medium.com/dunder-data/use-the-pandas-string-only-get-dummies-method-to-instantly-restructure-your-data-735e499a45a9">Use the Pandas String-Only get_dummies Method to Instantly Restructure your Data</a> was originally published in <a href="https://medium.com/dunder-data">Dunder Data</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Use this One Line of Code to Create Beautiful Data Visualizations in Python]]></title>
            <link>https://medium.com/dunder-data/use-this-one-line-of-code-to-create-beautiful-data-visualizations-in-python-61b624238fb0?source=rss-cf7f60f2eeb3------2</link>
            <guid isPermaLink="false">https://medium.com/p/61b624238fb0</guid>
            <category><![CDATA[data-science]]></category>
            <category><![CDATA[seaborn]]></category>
            <category><![CDATA[data-visualization]]></category>
            <category><![CDATA[python]]></category>
            <category><![CDATA[matplotlib]]></category>
            <dc:creator><![CDATA[Ted Petrou]]></dc:creator>
            <pubDate>Wed, 05 Oct 2022 14:13:29 GMT</pubDate>
            <atom:updated>2022-10-05T14:13:29.693Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*rL7mOeq9RiBVUOM-Fwm3KQ.jpeg" /></figure><p>In this post, you’ll learn the absolute quickest path to create beautiful data visualizations in Python. Specifically, we will be issuing a command from Seaborn, a popular library for creating static two-dimensional plots. We begin by reading in some data from Airbnb listings in Washington D.C.</p><pre>import pandas as pd<br>df = pd.read_csv(&#39;../../data/airbnb.csv&#39;, <br>                 usecols=[&#39;neighborhood&#39;, &#39;accommodates&#39;, &#39;price&#39;])<br>df.head()</pre><figure><img alt="png" src="https://cdn-images-1.medium.com/proxy/1*W-OyxwhLpeUhgQsuF0S1iw.png" /></figure><h4>Create the default box plot</h4><p>Here, we will use Seaborn to create a box plot of prices by neighborhood splitting by the number of persons the space accommodates.</p><pre>import seaborn as sns<br>sns.boxplot(x=&#39;neighborhood&#39;, y=&#39;price&#39;, hue=&#39;accommodates&#39;,  <br>            data=df);</pre><figure><img alt="png" src="https://cdn-images-1.medium.com/proxy/1*tHvyCBUFh8JCsJkY0L2NcA.png" /></figure><h4>The set_theme function</h4><p>While the default plot settings are not bad, they can be improved upon using a single command and that is with the set_theme function in Seaborn. By default, it will use the <a href="https://seaborn.pydata.org/tutorial/aesthetics.html#seaborn-figure-styles">darkgrid style</a> along with the <a href="https://seaborn.pydata.org/tutorial/color_palettes.html#qualitative-color-palettes">deep color palette</a>.</p><pre>sns.set_theme()</pre><p>After running this command, the same plot will appear substantially different.</p><pre>sns.boxplot(x=&#39;neighborhood&#39;, y=&#39;price&#39;, hue=&#39;accommodates&#39;, <br>            data=df);</pre><figure><img alt="png" src="https://cdn-images-1.medium.com/proxy/1*TzfmyxlauKn_h4tdEfohwA.png" /></figure><h4>Customizing matplotlib run configuration settings</h4><p>You may call the set_theme function without arguments, but I suggest increasing the DPI (dots per square inch) and reducing the font scale. The default DPI is 100 for matplotlib (the library Seaborn uses for all of its plotting), which is a lower resolution than most modern monitors and is the reason why the default image size (6.4 inches by 4.8 inches) does not match the actual screen inches on your monitor.</p><p>Any plot settings (formally, the <a href="https://seaborn.pydata.org/tutorial/aesthetics.html#seaborn-figure-styles">matplotlib run configuration parameters</a>) are able to changed with the rc parameter. Here, the DPI is increased to 150 and the default figure size decreased.</p><pre>sns.set_theme(rc={&#39;figure.dpi&#39;: 150, &#39;figure.figsize&#39;: (5, 3.75)})<br>sns.boxplot(x=&#39;neighborhood&#39;, y=&#39;price&#39;, hue=&#39;accommodates&#39;, <br>            data=df);</pre><figure><img alt="png" src="https://cdn-images-1.medium.com/proxy/1*2c8wRpUgwiZcsP5Ga1kq3w.png" /></figure><h4>Scaling the font</h4><p>While the image is sharper and larger, the text is clearly too big. The set_theme function provides a font_scale parameter to decrease the relative size of the text in the image. Here we set it to 0.65.</p><pre>sns.set_theme(rc={&#39;figure.dpi&#39;: 150, &#39;figure.figsize&#39;: (5, 3.75)}, <br>              font_scale=0.65)<br>sns.boxplot(x=&#39;neighborhood&#39;, y=&#39;price&#39;, hue=&#39;accommodates&#39;, <br>            data=df);</pre><figure><img alt="png" src="https://cdn-images-1.medium.com/proxy/1*TMe-tA6QQxHYYx5AnmgaAQ.png" /></figure><h4>Choosing other styles and color palettes</h4><p>There are several built-in styles (white, dark, whitegrid, darkgrid, ticks) as well as color palettes (deep, muted, bright, pastel, dark, colorblind) available as well. Here, we choose the whitegrid style paired with the pastel color palette.</p><pre>sns.set_theme(style=&#39;whitegrid&#39;, <br>              palette=&#39;pastel&#39;, <br>              rc={&#39;figure.dpi&#39;: 150, &#39;figure.figsize&#39;: (5, 3.75)}, <br>              font_scale=0.65)<br>sns.boxplot(x=&#39;neighborhood&#39;, y=&#39;price&#39;, hue=&#39;accommodates&#39;, <br>            data=df);</pre><figure><img alt="png" src="https://cdn-images-1.medium.com/proxy/1*GMY8fnIY0cOe8Z1phgIUsQ.png" /></figure><h4>Summary</h4><p>In summary, use the set_theme function in Seaborn to easily choose a style, color palette, customize the matplotlib run configuration settings and to scale the font.</p><h3>Master Python, Data Science and Machine Learning</h3><p>Immerse yourself in my comprehensive path for mastering data science and machine learning with Python. <a href="https://www.dunderdata.com/all-access-pass"><strong>Purchase the All Access Pass to get lifetime access to all current and future courses</strong></a><strong>.</strong> Some of the courses it contains:</p><ul><li><a href="https://www.dunderdata.com/master-the-fundamentals-of-python"><strong>Master the Fundamentals of Python</strong> </a>— A comprehensive introduction to Python (300+ pages, 150+ exercises, 25 hours of video)</li><li><a href="https://www.dunderdata.com/master-data-analysis-with-python"><strong>Master Data Analysis with Python</strong> </a>— The most comprehensive course available to learn pandas. (800+ pages and 500+ exercises, 10 hours of video)</li><li><a href="https://www.dunderdata.com/master-machine-learning-with-python"><strong>Master Machine Learning with Python </strong></a>— A deep dive into doing machine learning with scikit-learn constantly updated to showcase the latest and greatest tools. (300+ pages)</li></ul><p><a href="https://www.dunderdata.com/all-access-pass"><strong>Get the All Access Pass now!</strong></a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=61b624238fb0" width="1" height="1" alt=""><hr><p><a href="https://medium.com/dunder-data/use-this-one-line-of-code-to-create-beautiful-data-visualizations-in-python-61b624238fb0">Use this One Line of Code to Create Beautiful Data Visualizations in Python</a> was originally published in <a href="https://medium.com/dunder-data">Dunder Data</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How to become an Expert at Pandas for Data Analysis for FREE]]></title>
            <link>https://medium.com/dunder-data/how-to-become-an-expert-at-pandas-for-data-analysis-for-free-2cf6f4496f10?source=rss-cf7f60f2eeb3------2</link>
            <guid isPermaLink="false">https://medium.com/p/2cf6f4496f10</guid>
            <category><![CDATA[data-analysis]]></category>
            <category><![CDATA[data-science]]></category>
            <category><![CDATA[python]]></category>
            <category><![CDATA[pandas]]></category>
            <dc:creator><![CDATA[Ted Petrou]]></dc:creator>
            <pubDate>Tue, 21 Jun 2022 15:04:06 GMT</pubDate>
            <atom:updated>2022-06-21T15:04:06.269Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*qPkL0rTcBBWJ3UEglEl8WQ.jpeg" /></figure><p>In 2014, I was first introduced to pandas and had no idea how to use it. By 2017, I had written the 500 page book Pandas Cookbook. This is roughly the path I took to mastering pandas for free:</p><ol><li>Read the official documentation</li><li>Practice examples in the documentation</li><li>Flashcards</li><li>Share a full data analysis with others</li><li>Answer old Stack Overflow Questions</li><li>Answer new Stack Overflow Questions</li><li>Teach others in-person or online</li><li>Write pandas blog posts</li><li>Repeat</li></ol><h3>Read the official documentation</h3><p>The <a href="https://pandas.pydata.org/docs/user_guide/index.html#user-guide">official pandas documentation</a> is often one of the best sources when learning any technical skill. The same is true for pandas. Start with user guide that takes you through all of the library.</p><h3>Practice examples in the documentation</h3><p>This should be done in tandem with reading. Use a new jupyter notebook for each section of the user guide. Make your own notes and write (not copy) the code. Experiment on your own with each example testing out the different parameter options.</p><h3>Flashcards</h3><p>Use a flashcard system <a href="https://apps.ankiweb.net/">such as Anki</a> to help become more familiar with the available attributes and methods. While Stack Overflow is a great resource, you’ll show mastery once you can do an entire data analysis without leaving your notebook.</p><h3>Share a full data analysis with others</h3><p>After you’ve played with the toy examples in the docs, find a small real-world dataset. Ask interesting questions and then answer them. Share your work with others to get feedback. <a href="https://www.kaggle.com/datasets">Kaggle datasets</a> are great for this.</p><h3>Answer old Stack Overflow Questions</h3><p><a href="https://stackoverflow.com/questions/tagged/pandas">Stack Overflow has nearly 250k questions tagged as pandas</a>, most of them having solutions. Read the question and answer them on your own. Then compare yours to the other solutions. Answer several hundred. Do not post your solution yet.</p><h3>Answer new Stack Overflow Questions</h3><p>Very few people vote on old Stack Overflow questions. Post your solution to new Stack Overflow questions. They will get answered quickly by others, so you may not get upvotes at first. Be patient and keep posting and reviewing other people’s solutions.</p><h3>Teach others in-person or online</h3><p>Start mentoring other people who are beginning pandas users. It’s very helpful to see beginners make mistakes and then to correct them.</p><h3>Write pandas blog posts</h3><p>Blog posts can really help solidify your knowledge as a whole. Divide up your posts into two categories: Those that focus on a specific pandas topic and those that focus on real world data analysis with pandas.</p><h3>Repeat</h3><p>By this point, you should have some pandas expertise, but as any skill in life, you’ll need continual practice to perfect your craft. Each one of these steps will need to be repeated in order to maintain and surpass your current level of expertise. For instance, I’ve lost track of all the times I’ve read through the official documentation. There is an enormous amount of features available to pandas users, and it’s difficult to retain all of it without repeated reference.</p><h3>Master Data Analysis with Python — A Comprehensive Learning Path</h3><p>For those that are looking for a more direct path, my book <a href="https://dunderdata.com/master-data-analysis-with-python">Master Data Analysis with Python</a> is a comprehensive guide with hundreds of exercises, projects, solutions, and video lessons.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=2cf6f4496f10" width="1" height="1" alt=""><hr><p><a href="https://medium.com/dunder-data/how-to-become-an-expert-at-pandas-for-data-analysis-for-free-2cf6f4496f10">How to become an Expert at Pandas for Data Analysis for FREE</a> was originally published in <a href="https://medium.com/dunder-data">Dunder Data</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Awesome Pandas Tricks — Advent of Code Problems 1–5]]></title>
            <link>https://medium.com/dunder-data/awesome-pandas-tricks-advent-of-code-problems-1-5-bb57a040cc69?source=rss-cf7f60f2eeb3------2</link>
            <guid isPermaLink="false">https://medium.com/p/bb57a040cc69</guid>
            <category><![CDATA[python]]></category>
            <category><![CDATA[pandas]]></category>
            <category><![CDATA[data-science]]></category>
            <category><![CDATA[advent-of-code]]></category>
            <category><![CDATA[data-analysis]]></category>
            <dc:creator><![CDATA[Ted Petrou]]></dc:creator>
            <pubDate>Fri, 04 Mar 2022 20:05:18 GMT</pubDate>
            <atom:updated>2022-03-04T20:06:26.759Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*J389KXUWn1DO8wVKWQ4t5g.png" /></figure><h3>Awesome Pandas Tricks — Advent of Code Problems 1–5</h3><p>I have a new tutorial where I show interesting, unusual and just plain awesome ways to use the pandas library to solve data problems. Pandas is such a versatile library with so many ways to solve so many different problems.</p><p>The Advent of Code is a series of 25 fun problems released every December 1st, each containing some kind of data that require some sort of computing power to solve. While pandas is probably not the goto choice for these challenges, it is absolutely has the ability to solve these problems and often quite impressively. Many of these challenges require advanced and unusual usages of the pandas library, which is why I chose them for this tutorial. Hope you enjoy the tricks.</p><p>All of the material is located <a href="https://github.com/tdpetrou/Advent-of-Code-Pandas">here on GitHub</a> with the video below covering a detailed presentation of all of the tricks used to solve the problems.</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fwww.youtube.com%2Fembed%2F6aH4RMrhbVc%3Ffeature%3Doembed&amp;display_name=YouTube&amp;url=https%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3D6aH4RMrhbVc&amp;image=https%3A%2F%2Fi.ytimg.com%2Fvi%2F6aH4RMrhbVc%2Fhqdefault.jpg&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=youtube" width="640" height="480" frameborder="0" scrolling="no"><a href="https://medium.com/media/0c6bcebe174bb566b0b3c89bb0e61e4c/href">https://medium.com/media/0c6bcebe174bb566b0b3c89bb0e61e4c/href</a></iframe><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=bb57a040cc69" width="1" height="1" alt=""><hr><p><a href="https://medium.com/dunder-data/awesome-pandas-tricks-advent-of-code-problems-1-5-bb57a040cc69">Awesome Pandas Tricks — Advent of Code Problems 1–5</a> was originally published in <a href="https://medium.com/dunder-data">Dunder Data</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Data Types and Missing Values]]></title>
            <description><![CDATA[<div class="medium-feed-item"><p class="medium-feed-image"><a href="https://medium.com/dunder-data/data-types-and-missing-values-aa0003e51b27?source=rss-cf7f60f2eeb3------2"><img src="https://cdn-images-1.medium.com/max/1380/1*s1REnC74vKDukHPcF2bKng.png" width="1380"></a></p><p class="medium-feed-link"><a href="https://medium.com/dunder-data/data-types-and-missing-values-aa0003e51b27?source=rss-cf7f60f2eeb3------2">Continue reading on Dunder Data »</a></p></div>]]></description>
            <link>https://medium.com/dunder-data/data-types-and-missing-values-aa0003e51b27?source=rss-cf7f60f2eeb3------2</link>
            <guid isPermaLink="false">https://medium.com/p/aa0003e51b27</guid>
            <category><![CDATA[data-science]]></category>
            <category><![CDATA[pandas]]></category>
            <category><![CDATA[python]]></category>
            <dc:creator><![CDATA[Ted Petrou]]></dc:creator>
            <pubDate>Wed, 15 Dec 2021 14:31:58 GMT</pubDate>
            <atom:updated>2022-06-27T15:25:59.271Z</atom:updated>
        </item>
        <item>
            <title><![CDATA[The Pandas DataFrame and Series]]></title>
            <description><![CDATA[<div class="medium-feed-item"><p class="medium-feed-image"><a href="https://medium.com/dunder-data/the-pandas-dataframe-and-series-a7e7a5987492?source=rss-cf7f60f2eeb3------2"><img src="https://cdn-images-1.medium.com/max/1059/1*5zJ9tsVIRvxY83GsO8eyOw.png" width="1059"></a></p><p class="medium-feed-link"><a href="https://medium.com/dunder-data/the-pandas-dataframe-and-series-a7e7a5987492?source=rss-cf7f60f2eeb3------2">Continue reading on Dunder Data »</a></p></div>]]></description>
            <link>https://medium.com/dunder-data/the-pandas-dataframe-and-series-a7e7a5987492?source=rss-cf7f60f2eeb3------2</link>
            <guid isPermaLink="false">https://medium.com/p/a7e7a5987492</guid>
            <category><![CDATA[python]]></category>
            <category><![CDATA[data-science]]></category>
            <category><![CDATA[pandas]]></category>
            <dc:creator><![CDATA[Ted Petrou]]></dc:creator>
            <pubDate>Mon, 13 Dec 2021 19:22:41 GMT</pubDate>
            <atom:updated>2022-06-27T15:25:24.405Z</atom:updated>
        </item>
        <item>
            <title><![CDATA[Why Matplotlib Figure Inches Don’t Match Your Screen Inches and How to Fix it]]></title>
            <description><![CDATA[<div class="medium-feed-item"><p class="medium-feed-image"><a href="https://medium.com/dunder-data/why-matplotlib-figure-inches-dont-match-your-screen-inches-and-how-to-fix-it-993fa0417dba?source=rss-cf7f60f2eeb3------2"><img src="https://cdn-images-1.medium.com/max/600/1*LIeYNeqW6bcI5IWvpflrlA.png" width="600"></a></p><p class="medium-feed-snippet">If you&#x2019;ve worked with the matplotlib data visualization library before, then you&#x2019;ll be familiar with the term figsize, which is measured&#x2026;</p><p class="medium-feed-link"><a href="https://medium.com/dunder-data/why-matplotlib-figure-inches-dont-match-your-screen-inches-and-how-to-fix-it-993fa0417dba?source=rss-cf7f60f2eeb3------2">Continue reading on Dunder Data »</a></p></div>]]></description>
            <link>https://medium.com/dunder-data/why-matplotlib-figure-inches-dont-match-your-screen-inches-and-how-to-fix-it-993fa0417dba?source=rss-cf7f60f2eeb3------2</link>
            <guid isPermaLink="false">https://medium.com/p/993fa0417dba</guid>
            <category><![CDATA[matplotlib]]></category>
            <category><![CDATA[data-science]]></category>
            <category><![CDATA[data-visualization]]></category>
            <category><![CDATA[python]]></category>
            <dc:creator><![CDATA[Ted Petrou]]></dc:creator>
            <pubDate>Thu, 09 Dec 2021 19:17:44 GMT</pubDate>
            <atom:updated>2021-12-10T15:57:11.767Z</atom:updated>
        </item>
        <item>
            <title><![CDATA[Automatically Wrap Graph Labels in Matplotlib and Seaborn]]></title>
            <link>https://medium.com/dunder-data/automatically-wrap-graph-labels-in-matplotlib-and-seaborn-a48740bc9ce?source=rss-cf7f60f2eeb3------2</link>
            <guid isPermaLink="false">https://medium.com/p/a48740bc9ce</guid>
            <category><![CDATA[python]]></category>
            <category><![CDATA[matplotlib]]></category>
            <category><![CDATA[seaborn]]></category>
            <category><![CDATA[data-science]]></category>
            <category><![CDATA[data-visualization]]></category>
            <dc:creator><![CDATA[Ted Petrou]]></dc:creator>
            <pubDate>Tue, 07 Dec 2021 14:03:34 GMT</pubDate>
            <atom:updated>2021-12-07T15:26:55.068Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*wh8IdlFvEtLUEwGzhMioEA.png" /><figcaption>Before and after text wrapping of x-labels</figcaption></figure><p>If you’ve used matplotlib and seaborn to create data visualizations enough, then you’ve probably run into the issue of overlapping text labels on the x-axis.</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fwww.youtube.com%2Fembed%2FYDl52BsAOIc%3Ffeature%3Doembed&amp;display_name=YouTube&amp;url=https%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3DYDl52BsAOIc&amp;image=https%3A%2F%2Fi.ytimg.com%2Fvi%2FYDl52BsAOIc%2Fhqdefault.jpg&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=youtube" width="640" height="480" frameborder="0" scrolling="no"><a href="https://medium.com/media/6d86965bc08d18d42edffdcf300e3dbe/href">https://medium.com/media/6d86965bc08d18d42edffdcf300e3dbe/href</a></iframe><p>Let’s take a look at an example that uses Airbnb listings data.</p><pre>import pandas as pd<br>import matplotlib.pyplot as plt<br>import seaborn as sns<br><br>cols = [&#39;neighborhood&#39;, &#39;accommodates&#39;, &#39;price&#39;]<br>airbnb = pd.read_csv(&#39;data/airbnb.csv&#39;, usecols=cols)<br>airbnb.head()</pre><figure><img alt="png" src="https://cdn-images-1.medium.com/proxy/1*D68KXLErUL6mqppgPsTzGg.png" /></figure><p>After setting the theme, we create a bar plot of the mean price for the top 10 most frequent neighborhoods split by the number of people the listing accommodates.</p><pre>sns.set_theme(style=&#39;darkgrid&#39;, rc={&#39;figure.dpi&#39;: 147},              <br>              font_scale=0.7)<br>fig, ax = plt.subplots(figsize=(7, 2))<br>top10 = airbnb[&#39;neighborhood&#39;].value_counts().index[:10]<br>ax.set_title(&#39;Mean Price per Neighborhood&#39;)<br>sns.barplot(x=&#39;neighborhood&#39;, y=&#39;price&#39;, data=airbnb, ax=ax, <br>            order=top10, ci=None, <br>            hue=&#39;accommodates&#39;, hue_order=[1, 2, 3])<br>ax.legend(bbox_to_anchor=(1, 1), title=&#39;accommodates&#39;);</pre><figure><img alt="png" src="https://cdn-images-1.medium.com/proxy/1*D9M1c-kA7ToVekE4l9DBqA.png" /></figure><h4>Overlapping labels</h4><p>As you can see, most of the neighborhood names overlap one another making for an ugly graph. One solution is to rotate the labels 90 degrees.</p><pre>ax.set_xticklabels(ax.get_xticklabels(), rotation=90)<br>ax.figure</pre><figure><img alt="png" src="https://cdn-images-1.medium.com/proxy/1*xidw2g71jM_ehHqFIqfm4Q.png" /></figure><h4>Wrapping the labels</h4><p>Perhaps a better solution involves wrapping the labels at a given width. The below function uses the textwrap standard library to break strings at spaces at the given width, with the option to break in the middle of words.</p><pre>import textwrap<br>def wrap_labels(ax, width, break_long_words=False):<br>    labels = []<br>    for label in ax.get_xticklabels():<br>        text = label.get_text()<br>        labels.append(textwrap.fill(text, width=width,<br>                      break_long_words=break_long_words))<br>    ax.set_xticklabels(labels, rotation=0)</pre><p>We use the function to wrap the words at or before the 10th character.</p><pre>wrap_labels(ax, 10)<br>ax.figure</pre><figure><img alt="png" src="https://cdn-images-1.medium.com/proxy/1*5pzJcwyUZqFAsOdipp6-Zw.png" /></figure><h4>Master Data Analysis with Python</h4><p>If you enjoyed this tip, then check out my comprehensive book <a href="https://www.dunderdata.com/master-data-analysis-with-python">Master Data Analysis with Python</a> that teaches you how to become an expert at using Python and Pandas to do data analysis.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=a48740bc9ce" width="1" height="1" alt=""><hr><p><a href="https://medium.com/dunder-data/automatically-wrap-graph-labels-in-matplotlib-and-seaborn-a48740bc9ce">Automatically Wrap Graph Labels in Matplotlib and Seaborn</a> was originally published in <a href="https://medium.com/dunder-data">Dunder Data</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>