<?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 Daniel Rosa Mille on Medium]]></title>
        <description><![CDATA[Stories by Daniel Rosa Mille on Medium]]></description>
        <link>https://medium.com/@danielmille?source=rss-655f92e23a9c------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*V1bVFkvk7mX4xl_FFC8n9Q.jpeg</url>
            <title>Stories by Daniel Rosa Mille on Medium</title>
            <link>https://medium.com/@danielmille?source=rss-655f92e23a9c------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Thu, 03 Dec 2026 21:21:40 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@danielmille/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[A Quick Overview of Evaluation Metrics for Classification Models]]></title>
            <link>https://medium.com/geekculture/a-quick-overview-of-evaluation-metrics-for-classification-models-3aaa578113fb?source=rss-655f92e23a9c------2</link>
            <guid isPermaLink="false">https://medium.com/p/3aaa578113fb</guid>
            <category><![CDATA[ai]]></category>
            <category><![CDATA[classification-algorithms]]></category>
            <category><![CDATA[algorithms]]></category>
            <category><![CDATA[machine-learning]]></category>
            <category><![CDATA[data-science]]></category>
            <dc:creator><![CDATA[Daniel Rosa Mille]]></dc:creator>
            <pubDate>Mon, 19 Apr 2021 13:14:47 GMT</pubDate>
            <atom:updated>2021-04-22T19:44:22.050Z</atom:updated>
            <content:encoded><![CDATA[<h3>A Complete Guide of Evaluation Metrics for Classification Models</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*9SiEiL1icBdrJoTh" /><figcaption>Photo by <a href="https://unsplash.com/@emilymorter?utm_source=medium&amp;utm_medium=referral">Emily Morter</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><p>Dataset is cleaned and organized, model trained and you’re ready to check how damn fucking good is your model! But, <strong>what would be the best evaluation metric for your business model???</strong></p><p>If you’re like me, who lack a little help from google every time you need to remember a concept, <strong>I’ll give you free advice! </strong>Write down is one of the best strategies to <em>memorize</em> something! And that’s the reason why I’m writing this article! Firstly to <em>memorize</em> the concepts, secondly to have all the information about a topic in the same page for further queries and<strong> last but not least</strong> to <strong>share knowledge with data science community.</strong></p><p>In this article I’ll cover the main evaluation metrics for <strong>binary classification models</strong>. In the near future, I’ll be writing about the key evaluation metrics for regression models, but at this time this is not the assumption.</p><p>Hereupon, fasten your seatbelts and <strong>let’s see the metrics!!</strong></p><h4>Accuracy</h4><p>Accuracy is probably the most known metric to evaluate machine learning models. Even if you’ve never worked with data science <strong>you might know and use</strong> accuracy to evaluate your task performances!</p><p>Accuracy measures the number of samples that were correctly predicted over the size of the sample. For instance, suppose you want to predict in a population of 100 persons who is going to order pizza on a friday night (<em>in my neighboorhood that would be a very inbalanced dataset!</em>). The model predicted that 45 persons would order and 55 would not, for those 45 that the model predicted that would order pizza only 35 in fact ordered! From the 55 that the model predicted would not order pizza only 45 did not order.</p><p>In this example the model got 80 samples correctly predicted over the population of 100 persons, in this case the accuracy for this model is 80% (80/100).</p><p>What if, for the same population, we are predicting who will win the lottery?<strong><em> </em></strong>If the model just predict “No” all the time the accuracy would be 99,9%!</p><p>For this situation, where the data has inbalanced classes the accuracy is not a good choice but there are better options as you can see shortly.</p><h4>Precision</h4><p>Precision is the ability of the classifier not to label as positive a sample that is negative. In other words, precision is the metric that answer the question: <strong><em>“From all the instances the model predicted as positive, how many actually are positive?”</em></strong></p><p>Suppose you are trying to predict, from a population of 100 persons, who is going to travel to the Beach in the winter. Your model predicted everybody (100 persons) would go to the beach, but in fact only <strong>10 persons went to the beach</strong> in the winter. These <strong>10 persons</strong> are called <strong>True Positive</strong>, the model predicted they would go to the beach and they did it! <strong>The other 90</strong> that didn’t go to the beach <strong>are called False Positives.</strong></p><p>In the example above the <em>model precision is 10%</em> (10/(10+90)).</p><h4>Recall</h4><p>Recall is the ability of the classifier to find all the positive samples. In other words, recall is the metric that answer the question: <strong><em>“From all the instances that belongs to positive class, how many the model labeled as positive?”</em></strong></p><p>For instance, imagine you want to predict who is going to vote on candidate “A” next election. In a population of 100 persons, 10 indeed voted candidate “A”. Supposing the model labeled all 100 persons as positive (voted candidate “A”) the recall would be 100% because the model found all the positive cases.</p><p>In the other hand in the example above the model precision would be only 10%. (10 True Positive over 100 labeled as Positive)</p><p><strong>When to use Precision and When to use Recall?:</strong></p><p><strong>Precision </strong>is about being precise! So even if we managed to capture only one positive class instance, and we captured it correctly, then we are 100% precise.</p><p><strong>Recall </strong>is not so much about capturing cases correctly but more about capturing all cases that belongs to positive class. So if we simply always say every case is positive, we have 100% recall.</p><p>So basically, if we want to focus more on minimising False Negatives, we would want our Recall to be as close to 100% as possible, without precision being too bad, and if we want to focus on minimising False positives, then our focus should be to make Precision as close to 100% as possible.</p><h4>Specificity</h4><p>Specificity is a measure of how well the model can identify true negatives, it is the ratio of the true negatives out of all the samples that do not belong to positive class (true negatives and false positives). It is a measure that answer the question: <strong><em>“From all the instances that belongs to negative class, how many the model labeled as negative?”</em></strong></p><p>In the election model example, the idea of specificity would be to identify who would not vote on candidate “A”.</p><h4><strong>Confusion Matrix</strong></h4><p>Confusion matrix is a well detailed metric that brings True Positive (TP), False Negative (FN), False Positive (FP) and True Negative (TN) values. It is a very good footprint of how your model is performing. <strong>With the information provided by confusion matrix you are able to calculate all metrics mentioned above!</strong></p><p>Below you can find a very good visual representation of confusion matrix with all the formulas of previously mentioned metrics.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/850/1*K8Kw1erNh45mNPlDliVoaQ.png" /></figure><h4>F1 score</h4><p>F1 score is the weighted average (or Harmonic Mean) of Precision and Recall. While the arithmetic mean gives the same weight for both values, <em>the harmonic mean gives more emphasis for low values</em>, this way, <strong>to achieve a good F1 score the model must have a good Precion and Recall values</strong>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/376/1*cdmfghgZw3d7-rm0YYZPAQ.png" /></figure><p>A variation of F1 score is called F-beta. We define the value of Beta greater than 1 when we want to emphasize that the model must prioritize a better recall in comparison to precision.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/223/0*ByK-SYYTjGkNL2Xd.png" /></figure><p>Imagine you are training a model to identify persons with a rare disease. The model needs to make sure that all the positive instances will be labeled correctly even if it would cost some negative instances being labeled as positive as well. In this case is benefit to use a Beta value higher than 1.</p><h4>ROC AUC Score</h4><p>ROC Curve is a probability curve that plots the <strong>TPR (true positive rate or Sensitivity) </strong>against <strong>FPR (false positive rate or 1-Specificity) </strong>at various threshold values and essentially <strong>separates the ‘signal’ from the ‘noise’</strong>. The <strong>Area Under the Curve (AUC) </strong>is the measure of the ability of a classifier to distinguish between classes and is used as a summary of the ROC curve.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/289/1*jbf_0S8JA_YpwlEaN66MQA.png" /></figure><p>When AUC = 1, then the classifier is able to perfectly distinguish between the classes. If, however, the AUC had been 0, then the classifier would be predicting all Negatives as Positives, and all Positives as Negatives.</p><p>When AUC = 0.5, then the classifier is not able to distinguish between classes. Meaning either the classifier is predicting random class or constant class for all the data points.</p><h4>LogLoss</h4><p><strong>Log Loss</strong> is the most important classification metric based on probabilities. It <strong>heavily penalizes classifiers that are confident about an incorrect classification! </strong><em>But what does it mean??</em></p><p>It means that <strong>if for a particular positive sample, the model assigns it a very small probability to belongs to positive class then the corresponding contribution of this sample will be very large</strong> (as you can see on below image) and this is going to have a hige impact on the overall model performance.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/800/0*U6VJXIB0WMd5qxvH.png" /></figure><p>Log loss has no upper bound and it varies from 0 to infinite. When the value is near 0 indicates good accuracy, while log loss far from 0 indicates low accuracy.</p><h4>Matthews Correlation Coefficient (MCC)</h4><p>The Matthews correlation coefficient — <strong>MCC</strong>, is a metric that <strong>takes into account all the possibilities covered by confusion matrix (TP, TN, FP and FN)</strong> and is generally regarded as <strong>a balanced measure</strong> <strong>which can be used even if the classes are of very different sizes</strong> (inbalanced dataset). The MCC values varies between -1 and +1 where +1 represents a perfect prediction, -1 represents an inverse prediction and 0 and average random prediction.</p><p>The MCC formula is shown below:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/557/0*bBtItSiJ2V6sL3J7.png" /></figure><p>If you want to know more about MCC I recommend you to read this article:</p><p><a href="https://bmcgenomics.biomedcentral.com/articles/10.1186/s12864-019-6413-7#:~:text=The%20Matthews%20correlation%20coefficient%20(MCC)%2C%20instead%2C%20is%20a,both%20to%20the%20size%20of">The advantages of the Matthews correlation coefficient (MCC) over F1 score and accuracy in binary classification evaluation</a></p><h3>Conclusion</h3><p>In this article I covered the most used evaluation metrics for binary classification models! I tried to bring the concepts in a superficial way, <strong>but I truly encourage you to go deeper on each metric.</strong></p><p>I hope this article helps you someway on future ML performance metric definition or at least to remember you some concepts that were somehow lost in your mind!</p><p>If you liked this article do not hesitate to clap! And if you have any doubt or claim feel free to use the comments!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=3aaa578113fb" width="1" height="1" alt=""><hr><p><a href="https://medium.com/geekculture/a-quick-overview-of-evaluation-metrics-for-classification-models-3aaa578113fb">A Quick Overview of Evaluation Metrics for Classification Models</a> was originally published in <a href="https://medium.com/geekculture">Geek Culture</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Grab a Coffee and Let Python Fill Out a Form for You]]></title>
            <link>https://medium.com/geekculture/grab-a-coffee-and-let-python-fill-out-a-form-for-you-79c141702a5e?source=rss-655f92e23a9c------2</link>
            <guid isPermaLink="false">https://medium.com/p/79c141702a5e</guid>
            <category><![CDATA[python]]></category>
            <category><![CDATA[forms]]></category>
            <category><![CDATA[data]]></category>
            <category><![CDATA[google]]></category>
            <category><![CDATA[data-science]]></category>
            <dc:creator><![CDATA[Daniel Rosa Mille]]></dc:creator>
            <pubDate>Mon, 05 Apr 2021 11:14:39 GMT</pubDate>
            <atom:updated>2021-04-23T11:01:07.396Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*H2eWGThjl7OQYxvZ" /><figcaption>Photo by <a href="https://unsplash.com/@nate_dumlao?utm_source=medium&amp;utm_medium=referral">Nathan Dumlao</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><p>How many times <strong>you’ve got yourself stucked in a exhaustive and extremely boring task </strong>of picking information in a google sheet (or excel file) and inserting part of the information in another google sheet?</p><p>This kind of task makes your days <strong>boring</strong>, and the excitment you had on first days at work starts to <em>fade away…</em><br>You think you could be working on <strong>more challenging tasks</strong>, or that you could be <strong>developing new skills or learning something new!</strong></p><p>In order to <strong>get rid of this boring stuff</strong>, let a simple for loopexecute the job for you!!</p><p>In this article I’ll show in details how to <em>automatically</em> fill out a Google Form (and then turn it on a Google Sheet) using Python language. In addition I’ll show how to read a Google Sheet using pandas.</p><h3>How to automatically fill out a Google Sheet</h3><p>The first step to fill out a google sheet automatically is to create a google form containing the fields that must be filled. (The form questions must represent the columns on google sheet with respectives data types).<br>Below you can see a google forms with 4 question that will represent the columns of my google sheet. (Name, Age, E-mail, Country)</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/394/1*oW75N8qMntBPIR2XIB9pCQ.png" /></figure><p>After this, you need to create a pre-filled link. To do so, on right-top of screen go to “More options” menu and click on “Get pre-filled link” button as shown below:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/173/1*2kcVU8-5jj4lrxisM1tLtQ.png" /></figure><p>As a next step you need to fill your form with information that represents each question, the information you insert will be used to identify which is the “entry” for that question as I’ll explain shortly. After you fill your form, at the end of the page click on “Get link” and copy the link.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/329/1*NCMtEgseRyVncvCrSGWcPw.png" /></figure><p>The link you copied will have the same structure as the link created by myself:</p><p><a href="https://docs.google.com/forms/d/e/1FAIpQLSd6mtyTunOr3hmJstMVRIZm8W0UbfY06zx5ZC-5dB95w0ihPA/viewform?usp=pp_url&amp;entry.316027912=Daniel+Mille&amp;entry.272409573=33&amp;entry.779187075=dmille@gmail.com&amp;entry.1382791830=Brazil">https://docs.google.com/forms/d/e/1FAIpQLSd6mtyTunOr3hmJstMVRIZm8W0UbfY06zx5ZC-5dB95w0ihPA/viewform?usp=pp_url&amp;entry.316027912=Daniel+Mille&amp;entry.272409573=33&amp;entry.779187075=dmille@gmail.com&amp;entry.1382791830=Brazil</a></p><p>Let’s split this url in parts!<br>Let’s call base_url everything that comes before the “/viewform?”. This way my base_url is:<br><a href="https://docs.google.com/forms/d/e/1FAIpQLSd6mtyTunOr3hmJstMVRIZm8W0UbfY06zx5ZC-5dB95w0ihPA/viewform?usp=pp_url&amp;entry.316027912=Daniel+Mille&amp;entry.272409573=33&amp;entry.779187075=dmille@gmail.com&amp;entry.1382791830=Brazil">https://docs.google.com/forms/d/e/1FAIpQLSd6mtyTunOr3hmJstMVRIZm8W0UbfY06zx5ZC-5dB95w0ihPA</a></p><p>Note that in the URL each entry has its respective identification number and next to it there is the value that we filled in our pre-filled link. For example the entry number 316027912 represents the name field answer on our form (Daniel+Mille). We are going to use those IDs to do our automation with Python.</p><p>Let’s check the code!</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/f409d33bde889d3dc640ad1b52ed2237/href">https://medium.com/media/f409d33bde889d3dc640ad1b52ed2237/href</a></iframe><p>The libraries we’re going to use are pandas and requests. First of all I created a function called post_form that will receive as arguments our base_url and adictionary containing the entries as key and the dataframe information as value. The function will return a request to post the dictionary information on the base_url.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/0022396e8d09878ac96918e8a138738c/href">https://medium.com/media/0022396e8d09878ac96918e8a138738c/href</a></iframe><p>On the top of code we have our base_url. On the second part I created a dataframe with the information we’re going to post on our google form, in case you already have a excel file with the information you want to post you don’t need to create a dataframe by yourself, just use your excel/csv file.</p><p>On the bottom of the code I used pandas iterrows to iterate trough our dataframe and use the information at each row to execute the post_function. Note that the second argument of the function is a dictionary with the four IDs of the pre-filled link and it’s respective values coming from dataframe rows.</p><p><strong>Congratulations!</strong> All the infromation from the dataframe was posted on the form and you can access it as a google sheet when you want!</p><h3>How to read a google sheet with Pandas</h3><p>The method to read a google sheet trough pandas is performed using read_excel (the same way you read a xlsx file). The difference is that instead of using a file path as argument you will use a google sheet url.</p><p>To do so, the google sheet must first be published to the web or to it’s users.<br>To illustrate I’ll read a public google sheet (make sure you won’t turn public a google sheet with sensitive information! Everybody that has the url will have access to the information)</p><p>In order to publish your google sheet, on the right top side of screen, click on Share button as you can see below:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/479/1*wkIngWYYXUkZY9p3CxkK_Q.png" /></figure><p>Then, on the “Get Link” field switch to “Anyone with the link”:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/394/1*YhtkvIprJtsOAdfVbTmVZA.png" /></figure><p>The last step is to publish to the web. On <em>file</em> select <em>“publish to the web”</em> option, then select the file extension and publish it! The url is what we are going to pass as argument to read this file with pandas</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/344/1*nG9Qp_i9vzlVbJdQ-TO34g.png" /></figure><p>Now that your google sheet is public to the web, use read_excel with the google sheet url to explore your data with pandas!</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/3fec39744d9b6683b08bc7da0278ff4a/href">https://medium.com/media/3fec39744d9b6683b08bc7da0278ff4a/href</a></iframe><h3>Final thoughts</h3><p><strong>Be careful with the information you publish to the web!<br></strong>Anyone with the link will be able to access the information contained on your google sheet. I made my spreadsheet public to show how the code works, but you can restrict your spreadsheet to people in your organization or just authorized people!</p><p>I hope you enjoyed this article and that you can get rid of those back and forth jobs!</p><p>If you liked this article do not hesitate to clap! And if you have any doubt or claim feel free to use the comments!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=79c141702a5e" width="1" height="1" alt=""><hr><p><a href="https://medium.com/geekculture/grab-a-coffee-and-let-python-fill-out-a-form-for-you-79c141702a5e">Grab a Coffee and Let Python Fill Out a Form for You</a> was originally published in <a href="https://medium.com/geekculture">Geek Culture</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[SQL for Data Science is way more than SELECT *]]></title>
            <link>https://danielmille.medium.com/sql-for-data-science-is-way-more-than-select-4474ce3790ae?source=rss-655f92e23a9c------2</link>
            <guid isPermaLink="false">https://medium.com/p/4474ce3790ae</guid>
            <category><![CDATA[machine-learning]]></category>
            <category><![CDATA[data-engineering]]></category>
            <category><![CDATA[sql]]></category>
            <category><![CDATA[data-science]]></category>
            <category><![CDATA[database]]></category>
            <dc:creator><![CDATA[Daniel Rosa Mille]]></dc:creator>
            <pubDate>Thu, 25 Mar 2021 11:01:12 GMT</pubDate>
            <atom:updated>2021-04-23T01:03:49.870Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="A beautiful view of the sky in the night with brigth stars" src="https://cdn-images-1.medium.com/max/1024/0*CISPSRcTzw5dSTJJ" /><figcaption>Photo by <a href="https://unsplash.com/@vincentiu?utm_source=medium&amp;utm_medium=referral">Vincentiu Solomon</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><p>So you have finished your Data Science course, you have learnt Python, Statistics, Linear Algebra, Machine Learning, Deep Learning, you are <strong>mastering</strong> the main libraries to explore data, you practiced a lot with Kaggle data, made an amazing portfolio and <strong>got a Data Scientist job!</strong><br>You are <strong>very excited</strong> to arrive on your first week at work, open the .csv or .xlsx files with pandas and start exploring the data! But, wait…<br><strong>“Where are the .csv/.xlsx files???”</strong></p><p>Nowadays all the companies store their data in structured or non-structured databases at a Cloud (AWS, Google Cloud, Azure) so it’s essential for a Data Scientist to master SQL and NoSQL languages to extract correctly the information from those databases.<br>Unfortunately, everything about SQL that was teached on your Data Science course was simple queries like the famous SELECT * FROM table!Well, it does work,<strong> but believe me</strong>, when you would be working with petabytes of information <strong>you won’t want</strong> to import two different tables to merge with pandas (In fact depending on you PC configuration you will not be able to).</p><p>For this reason I decided to write this article with some tips of SQL I learnt during the past 6 months working as Data Scientist.</p><h4><strong>1. Subqueries (Select statement with where clause calling another Select statement)</strong></h4><p>Imagine you work on a petshop and you want to know the Name, Age and Address of all the customers that have a dog, but customer information are in a table and pets information are in another table. You could bring both tables and merge with Python, <strong>but you are better than this!</strong> You can use a <em>subquery</em> to extract all the customer names that have a dog from table2 and then use those customer names as parameter of a WHERE clause to extract the desired information as example below:</p><pre>SELECT column_name, column_age, column_address<br>FROM table1<br>WHERE column_name IN (SELECT column_name<br>                      FROM table2<br>                      WHERE column_pet_type = &#39;dog&#39;)<br>ORDER BY column_age DESC</pre><p>The second select extracts the name of all customers that have a dog and use those names as parameters of WHERE clause on the first SELECT. Make sure that the subquery SELECT statement will return a single column otherwise the first SELECT statement will not work.<br>This way the time required to extract information from database will be faster than extracting all information and then joining tables.</p><h4><strong>2. Temporary Tables</strong></h4><p>A temporary table in SQL Server is a database table that exists temporarily on the server. It stores a subset of data from a normal table for a certain period of time. Let’s see an example:<br>Suppose you want the ID of all customer with a specific name and a specific age, unfortunately, your table does not have the age, but contains the birth date. You can transform the birth date column into age and store this information into a Temporary table and then use this Temporary table into the new query.</p><pre>SELECT column_id, <br>       column_name, <br>       DATEDIFF(hour, column_birth_date, GETDATE())/8766 AS Age<br>INTO #TemporaryTable<br>FROM table1</pre><pre>SELECT column_id<br>FROM #TemporaryTable<br>WHERE column_name = &#39;Daniel&#39;<br>AND Age = 33</pre><p>In the first part of the query I am transforming the column birth_date into Age using the function DATEDIFF and then storing the information INTO #TemporaryTable.<br>In the second part I’m using the Temporary table I have created to query column ID with a specific Age extracted from Temporary Table.</p><h4><strong>3. Parameterized Queries</strong></h4><p>A <strong>parameterized query</strong> (also known as a prepared statement) is a means of pre-compiling a SQL statement so that all you need to supply are the “parameters” that need to be inserted into the statement for it to be executed. It’s commonly used to avoid SQL injection attacks.<br>SQL injection is a web security vulnerability that allows an attacker to interfere with the queries that an application makes to its database. It generally allows an attacker to view data that they are not normally able to retrieve. In many cases, an attacker can modify or delete this data, causing persistent changes to the application’s content or behavior.<br>In the example below I’m passing as parameter to my query “name” and “age”, the syntax used is for Microsoft Server SQL (%(parameter)s), for other databases check their documentation to see proper syntax.</p><pre>import pandas as pd<br>import pymssql</pre><pre>query = &quot;&quot;&quot;SELECT column_name, column_address, <br>                  column_email, column_age<br>           FROM table1<br>           WHERE column_name = %(name)s<br>           AND column_age = %(age)s&quot;&quot;&quot;</pre><pre>conn = pymssql.connect(host, user, password, database)<br>dataframe = pd.read_sql(query, conn, <br>                        params = dict(name = &#39;Daniel&#39;, age = 33))<br>#Or if you execute the query using cursor<br>cur = conn.cursor()<br>cur.execute(query, params = dict(name = &#39;Daniel&#39;, age = 33))</pre><h3>Conclusion</h3><p>If you want to improve your code performance, deep dive on SQL fundamentals, this article only covers a very tinny part of what SQL can provide users.<br>I hope you enjoyed the article and learnt something new along the way.<br>If so, be sure to let me know in the comments.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=4474ce3790ae" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>