<?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 Guido Tournois on Medium]]></title>
        <description><![CDATA[Stories by Guido Tournois on Medium]]></description>
        <link>https://medium.com/@guido.tournois?source=rss-71809e2a86c6------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*ARTtf2Zgaz91tOKM</url>
            <title>Stories by Guido Tournois on Medium</title>
            <link>https://medium.com/@guido.tournois?source=rss-71809e2a86c6------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Wed, 02 Dec 2026 04:55:14 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@guido.tournois/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[From  PoC to  value generating data science product]]></title>
            <link>https://medium.com/data-science/closing-the-gap-between-a-proof-of-concept-and-a-value-generating-data-science-product-5668364dd887?source=rss-71809e2a86c6------2</link>
            <guid isPermaLink="false">https://medium.com/p/5668364dd887</guid>
            <category><![CDATA[business-value]]></category>
            <category><![CDATA[data-engineering]]></category>
            <category><![CDATA[production]]></category>
            <category><![CDATA[data-science]]></category>
            <category><![CDATA[machine-learning-engineer]]></category>
            <dc:creator><![CDATA[Guido Tournois]]></dc:creator>
            <pubDate>Fri, 27 Nov 2020 14:50:17 GMT</pubDate>
            <atom:updated>2021-02-02T18:48:02.317Z</atom:updated>
            <content:encoded><![CDATA[<h3>Closing the gap between a proof of concept and a value generating data science product</h3><h4>Lessons learnt putting data science in production, for managers of data science teams.</h4><p>Too many data science proof-of-concept projects (PoC) never deliver business value but end as a slick PowerPoint presentation complemented by an adequate codebase. Even though the business case may be strong and the results promising, many data science projects never reach a production stage. And this is not surprising! Closing the gap between a successful proof-of-concept and a data science product that continuously delivers value is hard. Very hard. As such, I altered my career path from being a data scientist to becoming a data engineer. I made it my mission to help companies in pursuit of this ambitious and challenging goal: productionization of data science. In this blog, I highlight the most important learnings from my journey so far, in the hope you can take advantage of them.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*o5Yk9U0AVKxjhhuT" /><figcaption>Photo by <a href="https://unsplash.com/@codyhiscox?utm_source=medium&amp;utm_medium=referral">Cody Hiscox</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><p>To be transparent, I have worked as a data science consultant for about two years and as a data engineer consultant for a year. In these years, about half of my data projects went to production, while the other half suffered the unfortunate fate described above. Note, as I am still very much learning myself, the following learnings are no guarantee for success, but they do reflect my perspective on the matter.</p><p>Firstly, as so many have said before me, in order for a data science project to be successful, I think you should have a good use case! That is to say, a use case with a good business case behind it,<strong> </strong>which is being supported by both end-users as well as higher management.</p><p>Secondly and maybe even more important, <em>hiring data engineers and machine learning engineers early in the process is key</em> in making data science successful within your organisation. Building the required infrastructure for machine learning products is hard and will take much time and effort. So, if you are committed to reap the benefits from artificial intelligence/data science, it is paramount you start building machine learning infrastructure as soon as possible.</p><blockquote>Closing the gap between a successful proof-of-concept and a data science product that continuously delivers value is hard. Very hard.</blockquote><h4>Learning 1: A good use case is important</h4><p>Many businesses invest in data science as it promises many valuable insights into your customers and business processes. Not to mention, everybody else is doing it so you might lose your competitive edge if you don’t start right now. However, developing data science capabilities and products is expensive. There has to be a well-thought-out business case opposite it. With a so-so use case you might get money for a proof of concept or a minimal viable product, but I am quite sure that in the long run, further development will hold.</p><p>In one of my projects I worked for a large loyalty company. With a team of 6 developers, we were building a recommender engine for a large Asia-based supermarket. Rather than starting with a PoC, we directly worked towards an end product. After six months of development, however, the board of the loyalty company decided recommending products was not part of the core business, i.e. the use case was no longer important for the company. As such, the plug was pulled and the project was stopped.</p><p>I think this experience provides us with two lessons:</p><ol><li>It is important to continuously evaluate whether the use case you are working on is important for your organisation and has a good business case, not just after a few months. With some forethought, the project described above would probably have never started, saving time, energy, and money.</li><li>Unless you truly believe your use case is perfect, you might want to start by doing a proof of concept project, rather than directly building the end product. That is, doing one or multiple PoC’s can help you determine what use case shows the best potential and might even lead to identifying that golden ticket idea.</li></ol><p>Thus, whenever you are planning to leverage data science for a certain use case, make sure to work out the business case behind it first and start small. To help you out, try answering the following questions: will an ideal/perfect prediction model actually deliver business value for your use case? And if so, how much? Is the use case aligned with the business and end-users? How much effort will it take to work out the use case? If you struggle finding answers to these questions, maybe you can think about fulfilling the <a href="https://www.mckinsey.com/business-functions/mckinsey-analytics/our-insights/analytics-translator#">analytics translator</a> role within your team.</p><h4>Learning 2: No data science product will go to production without commitment of end-uses and higher management</h4><p>Besides having a good use case, it is important stakeholders, managers and end-users are committed, not just interested. Too often, I have experienced teams not being met in their needs, whether data or infrastructure related, in which case none of the stakeholders actually took action to resolve any issues. Of course, this leads to extended development time, delaying delivery of any value and deteriorating the belief in data science as a whole. This is bad.</p><p>This issue became very clear at another company I worked for that heavily invested in data science. Together we worked on a variety of projects, some of which in a PoC stage, others heading towards production. We did, however, face an issue: we did not have access to an incoming flow of high-quality data, but had to use data dumps, generated with convoluted one-off scripts. That in itself does not necessarily need to be a problem. Especially in the development phase, using data dumps can quickly help to show business value. But, as we had already released a minimum viable product and were heading towards a production stage, we needed this incoming flow of high-quality data for our product to be successful. Together with many other teams we depended on a dedicated data lake team for building data pipelines. Unfortunately for us, our data sources were not prioritised over other business critical data sources. From my perspective, this was due to two factors:</p><ul><li>There was not enough pull from our stakeholders. Data science was part of the innovation department. Even though most of our stakeholders were very interested in our results, they did not press for increasing the priority of our much needed data. Making the projects successful was probably not business critical, which is why the perceived importance was too low.</li><li>There was not a big enough pull from the end-users. Not all end-users were involved in the development process. As such, after the release of our minimal viable product, half of the identified end-users did not see use of our tool and were reluctant to use it.</li></ul><p>These issues resulted in a delay over a year. In fact, last time I checked the data science product was still not running in production. Since then, I always ask myself: Will someone lay awake at night whenever this data science product won’t reach a production stage? If the answer to this question is “No”, it helps to manage expectations, because chances are the project won’t reach production any time soon.</p><blockquote>When you’re interested in something, you do it only when it’s convenient. When you’re committed to something, you accept no excuses; only results. — Kenneth Blanchard</blockquote><h4>Learning 3: There is much technical depth hidden in Machine Learning Systems (not to be confused with technical debt)</h4><p>A common understanding of the machine learning pipeline is: you collect data, you gather valuable insights, you train a fancy model and start doing inference for newly arriving data. Undoubtedly, these steps are part of the pipeline, but it is only the tip of the iceberg. The required infrastructure to build, run and manage production level machine learning systems is vast and complex, as illustrated in the diagram below. Note the actual size of the black “ML Code” box.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*R-RbL9AA5gLIfnaS.png" /><figcaption>Source: <a href="https://papers.nips.cc/paper/5656-hidden-technical-debt-in-machine-learning-systems">Hidden Technical Debt in Machine Learning Systems</a></figcaption></figure><p>While working as a data engineer for a large Dutch grocery company, I was part of a data science department with over 25 FTE data scientists and engineers working on a variety of projects. The company was quite advanced in terms of technology, quality data was accessible and the developed machine learning models showed good results. Still, none of the products were running in production. To me, the main cause seemed to be the sheer amount of engineering required to get these models in production was overlooked and underestimated. This hunch was confirmed when they opened multiple vacancies for senior data engineers and machine learning engineers.</p><p>To illustrate some of the complexity involved with deploying Machine Learning models, think about the following questions.</p><ul><li>How will your product interact with your other infrastructure? Just a dump of an Excel file with predictions usually doesn’t suffice. You probably need to build model serving infrastructure to act as an interface between the model code and the rest of your infrastructure.</li><li>How to guarantee your model is still predicting accurately? You should probably log and monitor all input data that is used for prediction as well as your predictions.</li><li>What do you do whenever a newly trained model doesn’t perform well? You probably want to leverage continuous integration and continuous deployment to easily roll back to a previous version of the model.</li><li>Whenever something breaks in your code, the serving system is down or other services you rely on disfunction, would you like to know what caused it? To find the cause, you need to have logging and monitoring in place for all your services.</li></ul><p>In other words, in order to generate business value with data science, not just the science needs to happen, but mainly a lot of engineering has to be done. Not building the model pipeline, but building machine learning infrastructure is in my opinion the biggest challenge when it comes to getting data science products in production.</p><p>Sure, your first proof of concept project may fail, but when you are committed to building successful machine learning products, you need to start building the required machine learning infrastructure as soon a possible. The risk of not doing so is to end up in the land of nothingness: your PoC was successful, but reaching a production setting is months away. Any momentum that you may have gained, might disappear and chances of reaching production are getting slimmer and slimmer. To prevent this from happening make sure to hire data and machine learning engineers early in the process and start building.</p><p>Lastly, when working on the PoC project, think ahead! There are many steps you can take that might increase the complexity of the PoC in the short run, but will greatly reduce the complexity of going to production later. For example: rather than writing long code blocks, write your code into small testable functions including doc strings or leverage standard logging libraries for debugging your code.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*-2RuRHhL9FmLrgWn" /><figcaption>Make sure the start developing machine learning infrastructure as soon as possible if you don’t want to end up in the land of nothingness. Photo by <a href="https://unsplash.com/@fastturtle?utm_source=medium&amp;utm_medium=referral">Robert Murray</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a>.</figcaption></figure><p>Make sure the start developing machine learning infrastructure as soon as possible if you don’t want to end up in the land of nothingness.</p><h4><strong>Conclusion</strong></h4><p>For most data science projects having a successful proof of concept and a value delivering product are two worlds apart. In this blog, I have highlighted some of my learnings and explained what aspects are most important for closing the gap between proof of concept projects and successful data science products. I would say, these are the main take-aways:</p><ol><li>Identify the best <em>use cases</em> and get the <em>business</em> and <em>end-users</em> on board. This is critical, as building a good machine learning product is not trivial and will take time and effort, and thus money.</li><li>Gather the appropriate capabilities. Make sure not just to hire data scientists, but also analytics translators, machine learning engineers data engineers (note I am referring to capabilities, they don’t necessarily need to be different persons).</li><li>Start building machine learning infrastructure from the get-go as much engineering work is needed to get from a PoC to that money machine you are envisioning.</li></ol><p>I hope you can put my learnings to good use! Disregard them and you might just end up with expensive math 😉.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=5668364dd887" width="1" height="1" alt=""><hr><p><a href="https://medium.com/data-science/closing-the-gap-between-a-proof-of-concept-and-a-value-generating-data-science-product-5668364dd887">From  PoC to  value generating data science product</a> was originally published in <a href="https://medium.com/data-science">TDS Archive</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[4 Strategies to Deal With Large Datasets Using Pandas]]></title>
            <link>https://medium.com/hackernoon/4-strategies-to-deal-with-large-datasets-using-pandas-af0d6377da51?source=rss-71809e2a86c6------2</link>
            <guid isPermaLink="false">https://medium.com/p/af0d6377da51</guid>
            <category><![CDATA[data-science]]></category>
            <dc:creator><![CDATA[Guido Tournois]]></dc:creator>
            <pubDate>Wed, 19 Dec 2018 08:01:01 GMT</pubDate>
            <atom:updated>2019-01-21T14:03:11.980Z</atom:updated>
            <content:encoded><![CDATA[<p><em>By Guido Tournois, Data Scientist at </em><a href="https://medium.com/vantageai"><em>Vantage AI</em></a></p><p>Every data scientist knows that data pre-processing and feature engineering is paramount for a successful data science project. Often, however, these steps are time-consuming and involve you waiting for computations to finish, keeping you from creating that awesome model. In this post we will look at a few tricks that intend to speed up your pandas data-crunching workflows by enabling Pandas to use your machine in an optimal way.</p><p>Pandas is a powerful, versatile and easy-to-use Python library for manipulating data structures. For many data scientists like me, it has become the go-to tool when it comes to exploring and pre-processing data, as well as for engineering the best predictive features. Even though Pandas is still rapidly improving, we see Pandas users reverting to alternative tools like Spark as datasets become too large to fit in RAM memory. It is unfortunate that you have to learn and use a different tool, only because you have too much data. Therefore, I looked into four strategies to handle those too large datasets, all without leaving the comfort of Pandas:</p><ul><li>Sampling</li><li>Chunking</li><li>Optimising Pandas dtypes</li><li>Parallelising Pandas with Dask</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/proxy/1*RGSIp4d2kvkPgs0LTttT0Q.jpeg" /><figcaption><strong>’Cause nobody wants to leave Pandas behind </strong>(© Thinkstock)</figcaption></figure><h4>Sampling</h4><p>The most simple option is sampling your dataset. This approach can be especially powerful during the exploration phase: how does the data look like? What features can I create? In other words, what works and what does not. Often a random sample of 10% of such a large dataset will already contain a lot of information. That raises the first question, do you actually need to process your entire dataset to train an adequate model?</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/99d007bfb38ed16af04cd9a65b9d7f24/href">https://medium.com/media/99d007bfb38ed16af04cd9a65b9d7f24/href</a></iframe><h4>Chunking</h4><p>If you do need to process all data, you can choose to split the data into a number of chunks (which in itself do fit in memory) and perform your data cleaning and feature engineering on each individual chunk. Moreover, depending on the type of model you want to use, you have two options:</p><ul><li>If the model of your choosing allows for partial fitting, you can incrementally train a model on the data of each chunk;</li><li>Train a model on each individual chunk. Subsequently, to score new unseen data, make a prediction with each model and take the average or majority vote as the final prediction.</li></ul><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/2a58c69b552c2cd28bffda991642db91/href">https://medium.com/media/2a58c69b552c2cd28bffda991642db91/href</a></iframe><h4>Optimise data types</h4><p>When loading data from file, Pandas automatically infers the datatypes. Very convenient of course, however, often these datatypes are not optimal and take up more memory than needed. We will go over the three most common datatypes used by Pandas — int, float and object — and show how to decrease their memory imprint while looking at an example.</p><p>As a default, Pandas sets the dtype of integers to int64, this datatype takes in 8 bytes and can represent humongous integers, from -9223372036854775808 to 9223372036854775807. Many times, however, integers represent countable entities, like number of cars or visitors per day. Those type of numbers can easily be represented in the four times smaller dtypeint16. If your data fits in the range -32768 to 32767 convert them to int16 to achieve a memory reduction of 75%! In case your data is positive and under 65535, go for the unsigned variant, uint16.</p><p>In the same way, the float class consists of float16, float32 and float64, where the latter is Pandas’ default. Float64 can represent both very small and large numbers with high precision, which makes it suitable for accurate calculations. Often, however, you find yourself working with already noisy data, like sensor data or data with limited precision from itself such as currency. Again, the smaller datatypes float32orfloat16 will serve many use case’s purpose and will reduce your memory imprint with 50%, respectively 75%.</p><p>Another way to drastically reduce the size of your Pandas Dataframe is to transform columns of dtype Object to category. Rather than having copies of the same string at many positions in your dataframe, pandas will have a single copy from each string and will use pointers under the hood that refer to these strings. However, notice, that if every row has a different string, this approach will not work.</p><p>In the notebook below, I demonstrate a dataframe memory imprint reduction from 88.4%, only by changing the datatypes.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/fe06295b98b23c642e98dd8e9dacf41a/href">https://medium.com/media/fe06295b98b23c642e98dd8e9dacf41a/href</a></iframe><h4>Dask Dataframe</h4><p>Another way of handling large dataframes, is by exploiting the fact that our machine has more than one core. For this purpose we use Dask, an open-source python project which parallelizes Numpy and Pandas. Under the hood, a Dask Dataframe consists of many Pandas dataframes that are manipulated in parallel. As most of the Pandas API is implemented, Dask has a very similar look and feel, making it easy to use for all who know Pandas.</p><figure><img alt="" src="https://cdn-images-1.medium.com/proxy/1*q6sALf9exENmQFmrFd-W9A.png" /><figcaption>Under the hood, a Dask Dataframe consists of many pandas DataFrames</figcaption></figure><p>A question that arises is, how can data that does not fit in memory while using Pandas, fit in memory when using Dask. The answer lies in the fact that Dask Dataframes and operations are lazy. This means, operations are not executed immediately, but rather build up a task graph. We can interpret this graph as the recipe for calculating the result. Upon calling the computemethod, the build-in Dask task scheduler coordinates partial loading and manipulation of data while making use of all cores. As soon as all intermediary results are computed, Dask combines them and returns the final result.</p><figure><img alt="" src="https://cdn-images-1.medium.com/proxy/1*NXx5YaZ7EDQeLLycdulyeA.png" /><figcaption>Is it art? It could be, it is Dasks running a variety of tasks in parallel on my machine with 6 cores (12 threads).</figcaption></figure><p>Without going into anymore detail, consider the example below in which I will do some data processing on the 2015 New York Yellow Taxi dataset. It consists of 12 .csv files of around 2GB each. To have a fair comparison I did the same processing steps also in Pandas. As the full dataset does not fit into memory, my laptop made intensive use of swap space and memory compression in order to make it work.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/d6754f6f06e59d416c851dce93ece564/href">https://medium.com/media/d6754f6f06e59d416c851dce93ece564/href</a></iframe><p>In the notebook above, we have performed some data manipulation tasks on quite a large dataset using both Pandas and Dask. We can see that the total run time for Pandas amounts to 19 minutes, whereas it only took 10 minutes with Dask, making it almost twice as fast. Moreover, as promised, the syntax and functions used by Dask matches Pandas’ almost 1-on-1, making it essentially trivial to write your Dask workflow if you know your Pandas.</p><h4><strong>Conclusion</strong></h4><p>In this post I have shown that not all is lost when your dataset is too large and you insist on using Pandas. Depending on your goal, you can overcome memory issues by applying one of the described strategies. For exploration purposes you are best off by sampling your data. In case you need to process all your data, try iterating over your data or optimising your datatypes. Is your dataset still too large and are you tired of getting coffee every time your calculations are running, then go for Dask to parallelise Pandas.</p><h4>About the author</h4><p><a href="https://medium.com/@guido.tournois">Guido Tournois</a> is a data scientist at <strong>Vantage AI</strong>, a data science consultancy company in the Netherlands. If you need help with creating machine learning models for your data, feel free to contact us at <a href="/service/mailto:info@vantage-ai.com"><strong>info@vantage-ai.com</strong></a>.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=af0d6377da51" width="1" height="1" alt=""><hr><p><a href="https://medium.com/hackernoon/4-strategies-to-deal-with-large-datasets-using-pandas-af0d6377da51">4 Strategies to Deal With Large Datasets Using Pandas</a> was originally published in <a href="https://medium.com/hackernoon">HackerNoon.com</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[4 Strategies to Deal With Large Datasets Using Pandas]]></title>
            <link>https://medium.com/vantageai/4-strategies-to-deal-with-large-datasets-using-pandas-84d7f0ac4a6c?source=rss-71809e2a86c6------2</link>
            <guid isPermaLink="false">https://medium.com/p/84d7f0ac4a6c</guid>
            <category><![CDATA[data-analysis]]></category>
            <category><![CDATA[dask]]></category>
            <category><![CDATA[pandas]]></category>
            <category><![CDATA[data-science]]></category>
            <dc:creator><![CDATA[Guido Tournois]]></dc:creator>
            <pubDate>Wed, 19 Dec 2018 08:01:01 GMT</pubDate>
            <atom:updated>2019-01-21T13:59:39.218Z</atom:updated>
            <content:encoded><![CDATA[<p><em>By Guido Tournois, Data Scientist at </em><a href="https://medium.com/vantageai"><em>Vantage AI</em></a></p><p>Every data scientist knows that data pre-processing and feature engineering is paramount for a successful data science project. Often, however, these steps are time-consuming and involve you waiting for computations to finish, keeping you from creating that awesome model. In this post we will look at a few tricks that intend to speed up your pandas data-crunching workflows by enabling Pandas to use your machine in an optimal way.</p><p>Pandas is a powerful, versatile and easy-to-use Python library for manipulating data structures. For many data scientists like me, it has become the go-to tool when it comes to exploring and pre-processing data, as well as for engineering the best predictive features. Even though Pandas is still rapidly improving, we see Pandas users reverting to alternative tools like Spark as datasets become too large to fit in RAM memory. It is unfortunate that you have to learn and use a different tool, only because you have too much data. Therefore, I looked into four strategies to handle those too large datasets, all without leaving the comfort of Pandas:</p><ul><li>Sampling</li><li>Chunking</li><li>Optimising Pandas dtypes</li><li>Parallelising Pandas with Dask</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/proxy/1*RGSIp4d2kvkPgs0LTttT0Q.jpeg" /><figcaption><strong>’Cause nobody wants to leave Pandas behind </strong>(© Thinkstock)</figcaption></figure><h4>Sampling</h4><p>The most simple option is sampling your dataset. This approach can be especially powerful during the exploration phase: how does the data look like? What features can I create? In other words, what works and what does not. Often a random sample of 10% of such a large dataset will already contain a lot of information. That raises the first question, do you actually need to process your entire dataset to train an adequate model?</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/99d007bfb38ed16af04cd9a65b9d7f24/href">https://medium.com/media/99d007bfb38ed16af04cd9a65b9d7f24/href</a></iframe><h4>Chunking</h4><p>If you do need to process all data, you can choose to split the data into a number of chunks (which in itself do fit in memory) and perform your data cleaning and feature engineering on each individual chunk. Moreover, depending on the type of model you want to use, you have two options:</p><ul><li>If the model of your choosing allows for partial fitting, you can incrementally train a model on the data of each chunk;</li><li>Train a model on each individual chunk. Subsequently, to score new unseen data, make a prediction with each model and take the average or majority vote as the final prediction.</li></ul><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/2a58c69b552c2cd28bffda991642db91/href">https://medium.com/media/2a58c69b552c2cd28bffda991642db91/href</a></iframe><h4>Optimise data types</h4><p>When loading data from file, Pandas automatically infers the datatypes. Very convenient of course, however, often these datatypes are not optimal and take up more memory than needed. We will go over the three most common datatypes used by Pandas — int, float and object — and show how to decrease their memory imprint while looking at an example.</p><p>As a default, Pandas sets the dtype of integers to int64, this datatype takes in 8 bytes and can represent humongous integers, from -9223372036854775808 to 9223372036854775807. Many times, however, integers represent countable entities, like number of cars or visitors per day. Those type of numbers can easily be represented in the four times smaller dtypeint16. If your data fits in the range -32768 to 32767 convert them to int16 to achieve a memory reduction of 75%! In case your data is positive and under 65535, go for the unsigned variant, uint16.</p><p>In the same way, the float class consists of float16, float32 and float64, where the latter is Pandas’ default. Float64 can represent both very small and large numbers with high precision, which makes it suitable for accurate calculations. Often, however, you find yourself working with already noisy data, like sensor data or data with limited precision from itself such as currency. Again, the smaller datatypes float32orfloat16 will serve many use case’s purpose and will reduce your memory imprint with 50%, respectively 75%.</p><p>Another way to drastically reduce the size of your Pandas Dataframe is to transform columns of dtype Object to category. Rather than having copies of the same string at many positions in your dataframe, pandas will have a single copy from each string and will use pointers under the hood that refer to these strings. However, notice, that if every row has a different string, this approach will not work.</p><p>In the notebook below, I demonstrate a dataframe memory imprint reduction from 88.4%, only by changing the datatypes.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/fe06295b98b23c642e98dd8e9dacf41a/href">https://medium.com/media/fe06295b98b23c642e98dd8e9dacf41a/href</a></iframe><h4>Dask Dataframe</h4><p>Another way of handling large dataframes, is by exploiting the fact that our machine has more than one core. For this purpose we use Dask, an open-source python project which parallelizes Numpy and Pandas. Under the hood, a Dask Dataframe consists of many Pandas dataframes that are manipulated in parallel. As most of the Pandas API is implemented, Dask has a very similar look and feel, making it easy to use for all who know Pandas.</p><figure><img alt="" src="https://cdn-images-1.medium.com/proxy/1*q6sALf9exENmQFmrFd-W9A.png" /><figcaption>Under the hood, a Dask Dataframe consists of many pandas DataFrames</figcaption></figure><p>A question that arises is, how can data that does not fit in memory while using Pandas, fit in memory when using Dask. The answer lies in the fact that Dask Dataframes and operations are lazy. This means, operations are not executed immediately, but rather build up a task graph. We can interpret this graph as the recipe for calculating the result. Upon calling the computemethod, the build-in Dask task scheduler coordinates partial loading and manipulation of data while making use of all cores. As soon as all intermediary results are computed, Dask combines them and returns the final result.</p><figure><img alt="" src="https://cdn-images-1.medium.com/proxy/1*NXx5YaZ7EDQeLLycdulyeA.png" /><figcaption>Is it art? It could be, it is Dasks running a variety of tasks in parallel on my machine with 6 cores (12 threads).</figcaption></figure><p>Without going into anymore detail, consider the example below in which I will do some data processing on the 2015 New York Yellow Taxi dataset. It consists of 12 .csv files of around 2GB each. To have a fair comparison I did the same processing steps also in Pandas. As the full dataset does not fit into memory, my laptop made intensive use of swap space and memory compression in order to make it work.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/d6754f6f06e59d416c851dce93ece564/href">https://medium.com/media/d6754f6f06e59d416c851dce93ece564/href</a></iframe><p>In the notebook above, we have performed some data manipulation tasks on quite a large dataset using both Pandas and Dask. We can see that the total run time for Pandas amounts to 19 minutes, whereas it only took 10 minutes with Dask, making it almost twice as fast. Moreover, as promised, the syntax and functions used by Dask matches Pandas’ almost 1-on-1, making it essentially trivial to write your Dask workflow if you know your Pandas.</p><h4>Conclusion</h4><p>In this post I have shown that not all is lost when your dataset is too large and you insist on using Pandas. Depending on your goal, you can overcome memory issues by applying one of the described strategies. For exploration purposes you are best off by sampling your data. In case you need to process all your data, try iterating over your data or optimising your datatypes. Is your dataset still too large and are you tired of getting coffee every time your calculations are running, then go for Dask to parallelise Pandas.</p><h4>About the author</h4><p><a href="https://medium.com/@guido.tournois">Guido Tournois</a> is a data scientist at <strong>Vantage AI</strong>, a data science consultancy company in the Netherlands. If you need help with creating machine learning models for your data, feel free to contact us at <a href="/service/mailto:info@vantage-ai.com"><strong>info@vantage-ai.com</strong></a>.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=84d7f0ac4a6c" width="1" height="1" alt=""><hr><p><a href="https://medium.com/vantageai/4-strategies-to-deal-with-large-datasets-using-pandas-84d7f0ac4a6c">4 Strategies to Deal With Large Datasets Using Pandas</a> was originally published in <a href="https://medium.com/vantageai">VantageAI</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>