{"id":22040,"date":"2023-07-26T09:16:00","date_gmt":"2023-07-26T07:16:00","guid":{"rendered":"https:\/\/www.codemotion.com\/magazine\/?p=22040"},"modified":"2023-07-25T18:16:40","modified_gmt":"2023-07-25T16:16:40","slug":"data-analysis-made-easy-mastering-pandas-for-insightful-results","status":"publish","type":"post","link":"https:\/\/www.codemotion.com\/magazine\/data-science\/data-analysis-made-easy-mastering-pandas-for-insightful-results\/","title":{"rendered":"Data Analysis Made Easy: Mastering Pandas for Insightful Results"},"content":{"rendered":"\n<p>When talking about data analysis, Pandas is surely the most powerful and widely used <a href=\"https:\/\/www.codemotion.com\/magazine\/languages\/python\/\" target=\"_blank\" aria-label=\" (opens in a new tab)\" rel=\"noreferrer noopener\" class=\"ek-link\">Python<\/a> library for data manipulation, cleaning, and preprocessing.<\/p>\n\n\n\n<p>Thanks to its features, in fact, we can work with tabular data, retrieving them from SQL databases or Excel spreadsheets, for example.<\/p>\n\n\n\n<p>Then, we have the possibility to manipulate and clean the data to prepare them for further analyses like plots, and also for <a href=\"https:\/\/www.codemotion.com\/magazine\/ai-ml\/machine-learning\/6-courses-to-dive-deep-into-machine-learning-in-2022\/\" target=\"_blank\" aria-label=\" (opens in a new tab)\" rel=\"noreferrer noopener\" class=\"ek-link\">Machine Learning<\/a>.<\/p>\n\n\n\n<p>In this article, we\u2019ll introduce Pandas and the concept of a Pandas data frame.<\/p>\n\n\n\n<p>Then, we\u2019ll show some of the features of Pandas with hands-on practical examples.<\/p>\n\n\n\n<h1 class=\"wp-block-heading\" id=\"h-introduction-to-pandas-and-data-frames\">Introduction to Pandas and data frames<\/h1>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"h-introducing-pandas\">Introducing Pandas<\/h2>\n\n\n\n<p>What actually Pandas is?<\/p>\n\n\n\n<p>Well, this is what the developers say on the <a href=\"https:\/\/pandas.pydata.org\/about\/\" target=\"_blank\" aria-label=\" (opens in a new tab)\" rel=\"noreferrer noopener\" class=\"ek-link\">Pandas website<\/a> about their mission:<\/p>\n\n\n\n<p><em>\u201cpandas aims to be the fundamental high-level building block for doing practical, real-world data analysis in Python. Additionally, it has the broader goal of becoming the most powerful and flexible open source data analysis\/manipulation tool available in any language.\u201d<\/em><\/p>\n\n\n\n<p>So, we\u2019re dealing with what aims to be the only library that will pop up in our minds when we think of the word \u201cdata analysis\u201d.<\/p>\n\n\n\n<p>And, to be honest, it is so.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"h-how-to-install-pandas\">How to install Pandas<\/h2>\n\n\n\n<p>There are a couple of ways to install Pandas on your machine.<\/p>\n\n\n\n<p>If you already have Python installed, you can install Pandas like so:<\/p>\n\n\n<pre class=\"wp-block-code\"><span><code class=\"hljs\">$ pip install pandas<\/code><\/span><\/pre>\n\n\n<p>The other way is to install Anaconda on your machine. This is my favorite way because it will install Python, Pandas, all the libraries related to Data Science and Machine Learning, and many more.<\/p>\n\n\n\n<p>So, by installing Anaconda, you practically won\u2019t need to install other Python libraries in the future.&nbsp;<\/p>\n\n\n\n<p>To discover how to install it on your machine, you can check out <a href=\"https:\/\/www.anaconda.com\/download\">their website here<\/a>.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"h-understanding-pandas-series-and-pandas-data-frames\">Understanding Pandas series and Pandas data frames<\/h2>\n\n\n\n<p>A data frame is a table, somehow like a spreadsheet, where we can organize and analyze data and information.<\/p>\n\n\n\n<p>In other words, we can think of a data frame as a container that holds and organizes data in columns and rows like so:<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/lh3.googleusercontent.com\/R8wN1cyAZiXVXanitFi7HaCpr4_-xsjnbdEa3rgUgD4gZB5uSiTUCvtnD9Ghlqghvht4GuzcMD_85YZk5jBc6WH91U1NXf-tgMm2FxrF2wY3RmTDZhSU8uEqVN9VgnVX9jKG2A_NHjbCz8pzjegODvg\" alt=\"\"\/><figcaption class=\"wp-element-caption\">A Pandas data frame. Image by Author.<\/figcaption><\/figure>\n\n\n\n<p><\/p>\n\n\n\n<p>So, a data frame is an ordered container of data that can be in the form of text or numbers, organized in columns and rows.<\/p>\n\n\n\n<p>In particular, any Pandas column is also called a \u201c<em>Pandas series<\/em>\u201d. So, another way to see a Pandas data frame is that it is an ordered collection of Pandas series.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"h-creating-and-visualizing-a-pandas-data-frame\">Creating and visualizing a Pandas data frame<\/h2>\n\n\n\n<p>To work with tabular data we have two possibilities:<\/p>\n\n\n\n<ol class=\"wp-block-list\">\n<li>The data have been created somewhere and stored in a file. We can open them in Pandas and use them.<\/li>\n\n\n\n<li>We can create a data frame ourselves and use it immediately.<\/li>\n<\/ol>\n\n\n\n<p>Here we\u2019re showing the second option, while the first will be shown in the next paragraph.<\/p>\n\n\n\n<p>In Pandas, we can create a data frame with the same syntax we\u2019d create a Python dictionary. So, suppose we want to create a data frame that stores the values regarding measured times, in seconds, of some people who made several trials running. We can do it like so:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-1\" data-shcb-language-name=\"PHP\" data-shcb-language-slug=\"php\"><span><code class=\"hljs language-php\">import pandas <span class=\"hljs-keyword\">as<\/span> pd\n\n<span class=\"hljs-comment\"># Create data frame<\/span>\ntimes = pd.DataFrame({<span class=\"hljs-string\">\"Jhon\"<\/span>:&#91;<span class=\"hljs-number\">20<\/span>, <span class=\"hljs-number\">18<\/span>, <span class=\"hljs-number\">36<\/span>], <span class=\"hljs-string\">\"Simon\"<\/span>:&#91;<span class=\"hljs-number\">15<\/span>, <span class=\"hljs-number\">21<\/span>, <span class=\"hljs-number\">19<\/span>], <span class=\"hljs-string\">\"Karen\"<\/span>:&#91;<span class=\"hljs-number\">22<\/span>, <span class=\"hljs-number\">19<\/span>, <span class=\"hljs-number\">16<\/span>]})\n\n<span class=\"hljs-comment\"># Show first 10 values<\/span>\ntimes.head()<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-1\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">PHP<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">php<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p>So, we import Pandas as \u201cpd\u201d, first. Then, we create a data frame with the method pd.DataFrame(), then we use the method head() to show the first 10 values of the data frame. This is what we obtain:<br><\/p>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/lh4.googleusercontent.com\/JzK6S7yN1CEUEFns2rJpeAZpU77LONf3wHwxOqZl-NK4z1XVDi9sQpxiIbeKVH9CQpyyiLSUBDFfWnmJf_jeE70w_bczA7zpEnK9ShsQWBSkkNB80eD-ueZpfH77eqe8hkaRXVj6uIZgWnF_zMs61gQ\" alt=\"\"\/><\/figure>\n\n\n\n<p><em>The data frame. Image by Author.<\/em><\/p>\n\n\n\n<p>Now, let\u2019s use some actual data to show some features of Pandas.<\/p>\n\n\n\n<h1 class=\"wp-block-heading\" id=\"h-data-manipulation-in-pandas-a-hands-on-tutorial-with-actual-data\">Data manipulation in Pandas: a hands-on tutorial with actual data<\/h1>\n\n\n\n<p>The best way to learn Pandas is by getting some data and putting our hands on the keyboard.&nbsp;<\/p>\n\n\n\n<p>To show some of its features, we\u2019ll get some data related to the world population (the file is downloadable from Kaggle <a href=\"https:\/\/www.kaggle.com\/datasets\/iamsouravbanerjee\/world-population-dataset\">here<\/a>) to analyze it.<\/p>\n\n\n\n<p>As we can see, the data are in the form of a CSV file. This is one of the most typical formats.<\/p>\n\n\n\n<p>Supposing we\u2019ve renamed the file \u201cpopulation.csv\u201d this is how we can open it and show the first five values for each column:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-2\" data-shcb-language-name=\"PHP\" data-shcb-language-slug=\"php\"><span><code class=\"hljs language-php\">import pandas <span class=\"hljs-keyword\">as<\/span> pd\n\n<span class=\"hljs-comment\"># Read CSV<\/span>\npopulation = pd.read_csv(<span class=\"hljs-string\">\"population.csv\"<\/span>)\n\n<span class=\"hljs-comment\"># Show head<\/span>\npopulation.head()<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-2\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">PHP<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">php<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p>And we get:<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/lh4.googleusercontent.com\/LyXI8ZqZfaTkhpTxIDvzD0Xkf7aeRvnBCk9C4NHUM_hMkIydsyw-7quRSzMlalCFzJzwlamVfTlAJNT2B-_G4n8H1dmSEZ5Ot7G08cCKTAbHTTaHnU6hiGDhOlC4O1F4WANwr4tyJSSCa0Z5lfonNqk\" alt=\"\"\/><\/figure>\n\n\n\n<p><em>The data frame of our data. Image by author.<\/em><\/p>\n\n\n\n<p>So, we have a data frame with \u201ca lot\u201d of columns. But how many columns does it have? And how many rows?<\/p>\n\n\n\n<p>To show this data, we can type the following:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-3\" data-shcb-language-name=\"CSS\" data-shcb-language-slug=\"css\"><span><code class=\"hljs language-css\"># <span class=\"hljs-selector-tag\">Show<\/span> <span class=\"hljs-selector-tag\">shape<\/span>\n<span class=\"hljs-selector-tag\">population<\/span><span class=\"hljs-selector-class\">.shape<\/span>\n\n&gt;&gt;&gt;\n\n\u00a0 \u00a0 (234, 17)<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-3\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">CSS<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">css<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p>So, our data frame has 234 rows and 17 columns.<\/p>\n\n\n\n<p>One of the things we have to deal with when analyzing data is null values.<\/p>\n\n\n\n<p>To check if we have any of them, we type the following:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-4\" data-shcb-language-name=\"PHP\" data-shcb-language-slug=\"php\"><span><code class=\"hljs language-php\"><span class=\"hljs-comment\"># Show Null values<\/span>\npopulation.isnull().sum()\n\n&gt;&gt;&gt;\n\n\u00a0 Rank \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 <span class=\"hljs-number\">0<\/span>\n\u00a0 CCA3 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 <span class=\"hljs-number\">0<\/span>\n\u00a0 Country\/Territory\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 <span class=\"hljs-number\">0<\/span>\n\u00a0 Capital\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 <span class=\"hljs-number\">0<\/span>\n\u00a0 Continent\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 <span class=\"hljs-number\">0<\/span>\n\u00a0 <span class=\"hljs-number\">2022<\/span> Population\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 <span class=\"hljs-number\">0<\/span>\n\u00a0 <span class=\"hljs-number\">2020<\/span> Population\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 <span class=\"hljs-number\">0<\/span>\n\u00a0 <span class=\"hljs-number\">2015<\/span> Population\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 <span class=\"hljs-number\">0<\/span>\n\u00a0 <span class=\"hljs-number\">2010<\/span> Population\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 <span class=\"hljs-number\">0<\/span>\n\u00a0 <span class=\"hljs-number\">2000<\/span> Population\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 <span class=\"hljs-number\">0<\/span>\n\u00a0 <span class=\"hljs-number\">1990<\/span> Population\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 <span class=\"hljs-number\">0<\/span>\n\u00a0 <span class=\"hljs-number\">1980<\/span> Population\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 <span class=\"hljs-number\">0<\/span>\n\u00a0 <span class=\"hljs-number\">1970<\/span> Population\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 <span class=\"hljs-number\">0<\/span>\n\u00a0 Area (km\u00b2) \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 <span class=\"hljs-number\">0<\/span>\n\u00a0 Density (per km\u00b2)\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 <span class=\"hljs-number\">0<\/span>\n\u00a0 Growth Rate\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 <span class=\"hljs-number\">0<\/span>\n\u00a0 World Population Percentage\u00a0 \u00a0 <span class=\"hljs-number\">0<\/span>\n\u00a0 dtype: int64<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-4\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">PHP<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">php<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p>And the result shows us that, for each column, we have 0 cells with null values. So, we can proceed with our analysis without worrying about nulls.<\/p>\n\n\n\n<p>Now, suppose we\u2019re not interested in all the columns of the data frame because we believe some of them provide data we\u2019re not interested in. We can create another data frame that has only the columns we want to analyze.<\/p>\n\n\n\n<p>For example, say that we\u2019re not interested in the following columns: \u201cRank\u201d and \u201cCCA3\u201d. We can decide to create another data frame without these two by tying the following:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-5\" data-shcb-language-name=\"JavaScript\" data-shcb-language-slug=\"javascript\"><span><code class=\"hljs language-javascript\">population = population.drop(&#91;<span class=\"hljs-string\">\"Rank\"<\/span>, <span class=\"hljs-string\">\"CCA3\"<\/span>], axis=<span class=\"hljs-number\">1<\/span>)<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-5\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">JavaScript<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">javascript<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p>So, with the drop() method, we drop the columns we\u2019re not interested in, but we also need to specify the axis. In Pandas, axis=1 represents the vertical direction, while axis=0 represents the horizontal direction (and we use it when we want to drop rows).<\/p>\n\n\n\n<p>Also, we don\u2019t like too much that a column is named \u201cCountry\/Territory\u201d because if we need to filter it we\u2019ll need to write the whole column name. So let\u2019s rename it:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-6\" data-shcb-language-name=\"JavaScript\" data-shcb-language-slug=\"javascript\"><span><code class=\"hljs language-javascript\">population = population.rename(columns={<span class=\"hljs-string\">\"Country\/Territory\"<\/span>:<span class=\"hljs-string\">\"Country\"<\/span>})<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-6\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">JavaScript<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">javascript<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p>Now, suppose we want to plot the population trend over time, related to the Asian top three countries for growth rate. In other words: we want to intercept the top three Asian countries for growth rate over time and we want to plot the population trend over time.<\/p>\n\n\n\n<p>We can do it like so:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-7\" data-shcb-language-name=\"PHP\" data-shcb-language-slug=\"php\"><span><code class=\"hljs language-php\">\n<span class=\"hljs-comment\"># Transpose the columns<\/span>\nasia_population_df = asia_population_df.transpose()\n\n<span class=\"hljs-comment\"># Select the Country in Asia<\/span>\nasia_population_df.columns = asia&#91;<span class=\"hljs-string\">\"Country\"<\/span>]\n\n<span class=\"hljs-comment\"># Create plot<\/span>\n<span class=\"hljs-comment\"># Select the top 3 Countries per growth rate in Asia<\/span>\ntop_3_population_df = asia_population_df&#91;top_3_countries&#91;<span class=\"hljs-string\">\"Country\"<\/span>]]\ntop_3_population_df.plot(figsize=(<span class=\"hljs-number\">10<\/span>, <span class=\"hljs-number\">6<\/span>))\n\n<span class=\"hljs-comment\"># Label title and axes<\/span>\nplt.title(<span class=\"hljs-string\">\"Population in Asia with the max growth rate\"<\/span>)\nplt.xlabel(<span class=\"hljs-string\">\"Year\"<\/span>)\nplt.ylabel(<span class=\"hljs-string\">\"Population\"<\/span>)\n\n<span class=\"hljs-comment\"># Show legend<\/span>\nplt.legend(loc=<span class=\"hljs-string\">\"upper left\"<\/span>)\n\n<span class=\"hljs-comment\">#\u00a0 Rotate x-axis values<\/span>\nplt.xticks(rotation = <span class=\"hljs-string\">'vertical'<\/span>)\n\n<span class=\"hljs-comment\"># Show plot<\/span>\nplt.show()<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-7\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">PHP<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">php<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p>And we get:<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/lh3.googleusercontent.com\/M5HHlTDjPQGxEFAXsDDiUx9d7t5b1J1Xzel1MiGUaLk9j8nqxOc6BTb2A2YnUOv9qJN5YZukC46p81W5W1bMfnZEKp2eSpTFuoPZGHvOlm9tyo8enIhMv2MBXU2AjgHglB1wig3oOtQCFEu1BTi90DE\" alt=\"\"\/><\/figure>\n\n\n\n<p><em>The trend we were searching for. Image by Author.<\/em><\/p>\n\n\n\n<p>So, in the above code we have:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Selected \u201cAsia\u201d in the Country column with population[population[&#8220;Continent&#8221;] == &#8220;Asia&#8221;]<\/li>\n\n\n\n<li>Sorted the data frame with the method sort_values(), choosing \u201cGrowth Rate\u201d as a column. We\u2019ve, then, selected the first three with the method head(3).<\/li>\n\n\n\n<li>Taken all the columns whose name ends with \u201cPopulation\u201d, with the method endswith(),&nbsp; and we\u2019ve created another data frame called asia_population_df.<\/li>\n\n\n\n<li>Ordered in temporal order the column with iloc().<\/li>\n\n\n\n<li>Transposed the columns with the method transpose(). This means that the columns containing the data related to the population over the years have now become rows: this way, we can plot these data in the horizontal axis.<\/li>\n\n\n\n<li>Selected Asia as Country with asia[&#8220;Country&#8221;].<\/li>\n\n\n\n<li>Selected the top three countries with [top_3_countries[&#8220;Country&#8221;], as we wanted.<\/li>\n\n\n\n<li>Used Matplotlib to plot the data.<\/li>\n<\/ul>\n\n\n\n<p>Now, suppose we want to show the population trend over the years related to the 5 Countries with the maximum value of \u201cWorld Population Percentage\u201d. We can do it like so:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-8\" data-shcb-language-name=\"PHP\" data-shcb-language-slug=\"php\"><span><code class=\"hljs language-php\">import matplotlib.pyplot <span class=\"hljs-keyword\">as<\/span> plt\n\n<span class=\"hljs-comment\"># Sort for pop. percentage<\/span>\npopulation = population.sort_values(by=<span class=\"hljs-string\">\"World Population Percentage\"<\/span>, ascending=<span class=\"hljs-keyword\">False<\/span>)\n\n<span class=\"hljs-comment\"># Top 5<\/span>\ntop_5_countries = population.head(<span class=\"hljs-number\">5<\/span>)\nfiltered_df = population&#91;population&#91;<span class=\"hljs-string\">\"Country\"<\/span>].isin(top_5_countries&#91;<span class=\"hljs-string\">\"Country\"<\/span>])]\n\n\n<span class=\"hljs-comment\"># Select the column with population values<\/span>\npopulation_columns = &#91;col <span class=\"hljs-keyword\">for<\/span> col in filtered_df.columns <span class=\"hljs-keyword\">if<\/span> col.endswith(<span class=\"hljs-string\">\"Population\"<\/span>)]\npopulation_df = filtered_df&#91;population_columns]\n\n<span class=\"hljs-comment\"># Order columns from 1970 to 2022<\/span>\npopulation_df = population_df.iloc&#91;:, ::<span class=\"hljs-number\">-1<\/span>]\n\n<span class=\"hljs-comment\"># Traspose the columns<\/span>\npopulation_df = population_df.transpose()\n\n<span class=\"hljs-comment\"># Filter for Country<\/span>\npopulation_df.columns = filtered_df&#91;<span class=\"hljs-string\">\"Country\"<\/span>]\n\n<span class=\"hljs-comment\"># Plot<\/span>\npopulation_df.plot.line(figsize=(<span class=\"hljs-number\">10<\/span>, <span class=\"hljs-number\">6<\/span>))\nplt.title(<span class=\"hljs-string\">\"Population trend over the years: top 5 Countries per World Population Percentage\"<\/span>)\nplt.xlabel(<span class=\"hljs-string\">\"Year\"<\/span>)\nplt.ylabel(<span class=\"hljs-string\">\"Population\"<\/span>)\n\n<span class=\"hljs-comment\">#\u00a0 Rotate x-axis values<\/span>\nplt.xticks(rotation = <span class=\"hljs-string\">'vertical'<\/span>)\n\n<span class=\"hljs-comment\"># Show legend<\/span>\nplt.legend(loc=<span class=\"hljs-string\">\"upper left\"<\/span>)\n\n<span class=\"hljs-comment\"># Show plot<\/span>\nplt.show()<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-8\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">PHP<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">php<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p>And we get:<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/lh5.googleusercontent.com\/bKAeOfqhYBTWAYiXwskaQR6P_UMYUPxOEgfRADUD1vQo9L7Jl269y25-KJ8LtmtT4bk5nUEOCkuSwcd2CTWTPQUKgEXqnqY4hrzGhZNX8OczfzqZi1TyFY4VkUtG-RnF88EFuOzQpK_HSTc76j4i-iw\" alt=\"\"\/><\/figure>\n\n\n\n<p><em>The trend we were searching for. Image by Author.<\/em><\/p>\n\n\n\n<p>The code is quite identical to the previous one. The only difference is that here we haven\u2019t filtered for any Country: we\u2019ve selected the top 5 Countries in the world for Population Percentage, and we\u2019ve plotted the population trend over the years.<\/p>\n\n\n\n<p>This plot, in particular, show how the population in China and India is growing fast over the years.<\/p>\n\n\n\n<h1 class=\"wp-block-heading\" id=\"h-conclusions\">Conclusions<\/h1>\n\n\n\n<p>In this article, we\u2019ve seen how we can use Pandas to manipulate the data to get insights from them, by plotting specific graphs.<\/p>\n\n\n\n<p>The best way to learn Pandas is to get some data we\u2019re interested in and, thanks to curiosity, explore them. This way we learn Pandas with a hands-on approach which is the only one that will help you learn it effectively.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>When talking about data analysis, Pandas is surely the most powerful and widely used Python library for data manipulation, cleaning, and preprocessing. Thanks to its features, in fact, we can work with tabular data, retrieving them from SQL databases or Excel spreadsheets, for example. Then, we have the possibility to manipulate and clean the data&#8230; <a class=\"more-link\" href=\"https:\/\/www.codemotion.com\/magazine\/data-science\/data-analysis-made-easy-mastering-pandas-for-insightful-results\/\">Read more<\/a><\/p>\n","protected":false},"author":171,"featured_media":21978,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_editorskit_title_hidden":false,"_editorskit_reading_time":0,"_editorskit_is_block_options_detached":false,"_editorskit_block_options_position":"{}","_uag_custom_page_level_css":"","_genesis_hide_title":false,"_genesis_hide_breadcrumbs":false,"_genesis_hide_singular_image":false,"_genesis_hide_footer_widgets":false,"_genesis_custom_body_class":"","_genesis_custom_post_class":"","_genesis_layout":"","footnotes":""},"categories":[8457],"tags":[4446,68],"collections":[],"class_list":{"0":"post-22040","1":"post","2":"type-post","3":"status-publish","4":"format-standard","5":"has-post-thumbnail","7":"category-data-science","8":"tag-data-analysis","9":"tag-python","10":"entry"},"yoast_head":"<!-- This site is optimized with the Yoast SEO Premium plugin v26.9 (Yoast SEO v27.5) - https:\/\/yoast.com\/product\/yoast-seo-premium-wordpress\/ -->\n<title>Discover How to Use the Pandas Python Library for Data Analysis<\/title>\n<meta name=\"description\" content=\"Data analysis takes a long time to learn, but the Pandas Library for Python can help you make the process smoother. Read on!\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.codemotion.com\/magazine\/data-science\/data-analysis-made-easy-mastering-pandas-for-insightful-results\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Data Analysis Made Easy: Mastering Pandas for Insightful Results\" \/>\n<meta property=\"og:description\" content=\"Data analysis takes a long time to learn, but the Pandas Library for Python can help you make the process smoother. Read on!\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.codemotion.com\/magazine\/data-science\/data-analysis-made-easy-mastering-pandas-for-insightful-results\/\" \/>\n<meta property=\"og:site_name\" content=\"Codemotion Magazine\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/Codemotion.Italy\/\" \/>\n<meta property=\"article:published_time\" content=\"2023-07-26T07:16:00+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.codemotion.com\/magazine\/wp-content\/uploads\/2023\/07\/iStock-1141236448-min.jpg\" \/>\n\t<meta property=\"og:image:width\" content=\"1183\" \/>\n\t<meta property=\"og:image:height\" content=\"887\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/jpeg\" \/>\n<meta name=\"author\" content=\"Federico Trotta\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@CodemotionIT\" \/>\n<meta name=\"twitter:site\" content=\"@CodemotionIT\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Federico Trotta\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"7 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/www.codemotion.com\\\/magazine\\\/data-science\\\/data-analysis-made-easy-mastering-pandas-for-insightful-results\\\/#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.codemotion.com\\\/magazine\\\/data-science\\\/data-analysis-made-easy-mastering-pandas-for-insightful-results\\\/\"},\"author\":{\"name\":\"Federico Trotta\",\"@id\":\"https:\\\/\\\/www.codemotion.com\\\/magazine\\\/#\\\/schema\\\/person\\\/98d2abaf70e7d106abab1f38bf20f90d\"},\"headline\":\"Data Analysis Made Easy: Mastering Pandas for Insightful Results\",\"datePublished\":\"2023-07-26T07:16:00+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/www.codemotion.com\\\/magazine\\\/data-science\\\/data-analysis-made-easy-mastering-pandas-for-insightful-results\\\/\"},\"wordCount\":1318,\"publisher\":{\"@id\":\"https:\\\/\\\/www.codemotion.com\\\/magazine\\\/#organization\"},\"image\":{\"@id\":\"https:\\\/\\\/www.codemotion.com\\\/magazine\\\/data-science\\\/data-analysis-made-easy-mastering-pandas-for-insightful-results\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/www.codemotion.com\\\/magazine\\\/wp-content\\\/uploads\\\/2023\\\/07\\\/iStock-1141236448-min.jpg\",\"keywords\":[\"Data Analysis\",\"Python\"],\"articleSection\":[\"Data Science\"],\"inLanguage\":\"en-US\"},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/www.codemotion.com\\\/magazine\\\/data-science\\\/data-analysis-made-easy-mastering-pandas-for-insightful-results\\\/\",\"url\":\"https:\\\/\\\/www.codemotion.com\\\/magazine\\\/data-science\\\/data-analysis-made-easy-mastering-pandas-for-insightful-results\\\/\",\"name\":\"Discover How to Use the Pandas Python Library for Data Analysis\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.codemotion.com\\\/magazine\\\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\\\/\\\/www.codemotion.com\\\/magazine\\\/data-science\\\/data-analysis-made-easy-mastering-pandas-for-insightful-results\\\/#primaryimage\"},\"image\":{\"@id\":\"https:\\\/\\\/www.codemotion.com\\\/magazine\\\/data-science\\\/data-analysis-made-easy-mastering-pandas-for-insightful-results\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/www.codemotion.com\\\/magazine\\\/wp-content\\\/uploads\\\/2023\\\/07\\\/iStock-1141236448-min.jpg\",\"datePublished\":\"2023-07-26T07:16:00+00:00\",\"description\":\"Data analysis takes a long time to learn, but the Pandas Library for Python can help you make the process smoother. Read on!\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/www.codemotion.com\\\/magazine\\\/data-science\\\/data-analysis-made-easy-mastering-pandas-for-insightful-results\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/www.codemotion.com\\\/magazine\\\/data-science\\\/data-analysis-made-easy-mastering-pandas-for-insightful-results\\\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/www.codemotion.com\\\/magazine\\\/data-science\\\/data-analysis-made-easy-mastering-pandas-for-insightful-results\\\/#primaryimage\",\"url\":\"https:\\\/\\\/www.codemotion.com\\\/magazine\\\/wp-content\\\/uploads\\\/2023\\\/07\\\/iStock-1141236448-min.jpg\",\"contentUrl\":\"https:\\\/\\\/www.codemotion.com\\\/magazine\\\/wp-content\\\/uploads\\\/2023\\\/07\\\/iStock-1141236448-min.jpg\",\"width\":1183,\"height\":887,\"caption\":\"analisi dati pandas\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/www.codemotion.com\\\/magazine\\\/data-science\\\/data-analysis-made-easy-mastering-pandas-for-insightful-results\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/www.codemotion.com\\\/magazine\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Data Science\",\"item\":\"https:\\\/\\\/www.codemotion.com\\\/magazine\\\/ai-ml\\\/data-science\\\/\"},{\"@type\":\"ListItem\",\"position\":3,\"name\":\"Data Analysis Made Easy: Mastering Pandas for Insightful Results\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/www.codemotion.com\\\/magazine\\\/#website\",\"url\":\"https:\\\/\\\/www.codemotion.com\\\/magazine\\\/\",\"name\":\"Codemotion Magazine\",\"description\":\"We code the future. Together\",\"publisher\":{\"@id\":\"https:\\\/\\\/www.codemotion.com\\\/magazine\\\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/www.codemotion.com\\\/magazine\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\\\/\\\/www.codemotion.com\\\/magazine\\\/#organization\",\"name\":\"Codemotion\",\"url\":\"https:\\\/\\\/www.codemotion.com\\\/magazine\\\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/www.codemotion.com\\\/magazine\\\/#\\\/schema\\\/logo\\\/image\\\/\",\"url\":\"https:\\\/\\\/www.codemotion.com\\\/magazine\\\/wp-content\\\/uploads\\\/2019\\\/11\\\/codemotionlogo.png\",\"contentUrl\":\"https:\\\/\\\/www.codemotion.com\\\/magazine\\\/wp-content\\\/uploads\\\/2019\\\/11\\\/codemotionlogo.png\",\"width\":225,\"height\":225,\"caption\":\"Codemotion\"},\"image\":{\"@id\":\"https:\\\/\\\/www.codemotion.com\\\/magazine\\\/#\\\/schema\\\/logo\\\/image\\\/\"},\"sameAs\":[\"https:\\\/\\\/www.facebook.com\\\/Codemotion.Italy\\\/\",\"https:\\\/\\\/x.com\\\/CodemotionIT\"]},{\"@type\":\"Person\",\"@id\":\"https:\\\/\\\/www.codemotion.com\\\/magazine\\\/#\\\/schema\\\/person\\\/98d2abaf70e7d106abab1f38bf20f90d\",\"name\":\"Federico Trotta\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/69bc8655986054bfe43c7eaa7f00e2ea939b761bd924064ea9b5972568a01714?s=96&d=mm&r=g\",\"url\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/69bc8655986054bfe43c7eaa7f00e2ea939b761bd924064ea9b5972568a01714?s=96&d=mm&r=g\",\"contentUrl\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/69bc8655986054bfe43c7eaa7f00e2ea939b761bd924064ea9b5972568a01714?s=96&d=mm&r=g\",\"caption\":\"Federico Trotta\"},\"description\":\"I have loved writing since I was a young boy in school, writing detective stories as class exams. Thanks to my curiosity, I discovered programming and AI. Having a burning passion for writing, I couldn't avoid starting to write about these topics, so I decided to change my career to become a Technical Writer. My purpose is to educate people on Python programming, Machine Learning, and Data Science, through writing.\",\"sameAs\":[\"https:\\\/\\\/federicotrotta.com\\\/\",\"https:\\\/\\\/www.linkedin.com\\\/in\\\/federico-trotta\\\/?originalSubdomain=it\"],\"url\":\"https:\\\/\\\/www.codemotion.com\\\/magazine\\\/author\\\/federico-trotta\\\/\"}]}<\/script>\n<!-- \/ Yoast SEO Premium plugin. -->","yoast_head_json":{"title":"Discover How to Use the Pandas Python Library for Data Analysis","description":"Data analysis takes a long time to learn, but the Pandas Library for Python can help you make the process smoother. Read on!","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.codemotion.com\/magazine\/data-science\/data-analysis-made-easy-mastering-pandas-for-insightful-results\/","og_locale":"en_US","og_type":"article","og_title":"Data Analysis Made Easy: Mastering Pandas for Insightful Results","og_description":"Data analysis takes a long time to learn, but the Pandas Library for Python can help you make the process smoother. Read on!","og_url":"https:\/\/www.codemotion.com\/magazine\/data-science\/data-analysis-made-easy-mastering-pandas-for-insightful-results\/","og_site_name":"Codemotion Magazine","article_publisher":"https:\/\/www.facebook.com\/Codemotion.Italy\/","article_published_time":"2023-07-26T07:16:00+00:00","og_image":[{"width":1183,"height":887,"url":"https:\/\/www.codemotion.com\/magazine\/wp-content\/uploads\/2023\/07\/iStock-1141236448-min.jpg","type":"image\/jpeg"}],"author":"Federico Trotta","twitter_card":"summary_large_image","twitter_creator":"@CodemotionIT","twitter_site":"@CodemotionIT","twitter_misc":{"Written by":"Federico Trotta","Est. reading time":"7 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.codemotion.com\/magazine\/data-science\/data-analysis-made-easy-mastering-pandas-for-insightful-results\/#article","isPartOf":{"@id":"https:\/\/www.codemotion.com\/magazine\/data-science\/data-analysis-made-easy-mastering-pandas-for-insightful-results\/"},"author":{"name":"Federico Trotta","@id":"https:\/\/www.codemotion.com\/magazine\/#\/schema\/person\/98d2abaf70e7d106abab1f38bf20f90d"},"headline":"Data Analysis Made Easy: Mastering Pandas for Insightful Results","datePublished":"2023-07-26T07:16:00+00:00","mainEntityOfPage":{"@id":"https:\/\/www.codemotion.com\/magazine\/data-science\/data-analysis-made-easy-mastering-pandas-for-insightful-results\/"},"wordCount":1318,"publisher":{"@id":"https:\/\/www.codemotion.com\/magazine\/#organization"},"image":{"@id":"https:\/\/www.codemotion.com\/magazine\/data-science\/data-analysis-made-easy-mastering-pandas-for-insightful-results\/#primaryimage"},"thumbnailUrl":"https:\/\/www.codemotion.com\/magazine\/wp-content\/uploads\/2023\/07\/iStock-1141236448-min.jpg","keywords":["Data Analysis","Python"],"articleSection":["Data Science"],"inLanguage":"en-US"},{"@type":"WebPage","@id":"https:\/\/www.codemotion.com\/magazine\/data-science\/data-analysis-made-easy-mastering-pandas-for-insightful-results\/","url":"https:\/\/www.codemotion.com\/magazine\/data-science\/data-analysis-made-easy-mastering-pandas-for-insightful-results\/","name":"Discover How to Use the Pandas Python Library for Data Analysis","isPartOf":{"@id":"https:\/\/www.codemotion.com\/magazine\/#website"},"primaryImageOfPage":{"@id":"https:\/\/www.codemotion.com\/magazine\/data-science\/data-analysis-made-easy-mastering-pandas-for-insightful-results\/#primaryimage"},"image":{"@id":"https:\/\/www.codemotion.com\/magazine\/data-science\/data-analysis-made-easy-mastering-pandas-for-insightful-results\/#primaryimage"},"thumbnailUrl":"https:\/\/www.codemotion.com\/magazine\/wp-content\/uploads\/2023\/07\/iStock-1141236448-min.jpg","datePublished":"2023-07-26T07:16:00+00:00","description":"Data analysis takes a long time to learn, but the Pandas Library for Python can help you make the process smoother. Read on!","breadcrumb":{"@id":"https:\/\/www.codemotion.com\/magazine\/data-science\/data-analysis-made-easy-mastering-pandas-for-insightful-results\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.codemotion.com\/magazine\/data-science\/data-analysis-made-easy-mastering-pandas-for-insightful-results\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.codemotion.com\/magazine\/data-science\/data-analysis-made-easy-mastering-pandas-for-insightful-results\/#primaryimage","url":"https:\/\/www.codemotion.com\/magazine\/wp-content\/uploads\/2023\/07\/iStock-1141236448-min.jpg","contentUrl":"https:\/\/www.codemotion.com\/magazine\/wp-content\/uploads\/2023\/07\/iStock-1141236448-min.jpg","width":1183,"height":887,"caption":"analisi dati pandas"},{"@type":"BreadcrumbList","@id":"https:\/\/www.codemotion.com\/magazine\/data-science\/data-analysis-made-easy-mastering-pandas-for-insightful-results\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.codemotion.com\/magazine\/"},{"@type":"ListItem","position":2,"name":"Data Science","item":"https:\/\/www.codemotion.com\/magazine\/ai-ml\/data-science\/"},{"@type":"ListItem","position":3,"name":"Data Analysis Made Easy: Mastering Pandas for Insightful Results"}]},{"@type":"WebSite","@id":"https:\/\/www.codemotion.com\/magazine\/#website","url":"https:\/\/www.codemotion.com\/magazine\/","name":"Codemotion Magazine","description":"We code the future. Together","publisher":{"@id":"https:\/\/www.codemotion.com\/magazine\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.codemotion.com\/magazine\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/www.codemotion.com\/magazine\/#organization","name":"Codemotion","url":"https:\/\/www.codemotion.com\/magazine\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.codemotion.com\/magazine\/#\/schema\/logo\/image\/","url":"https:\/\/www.codemotion.com\/magazine\/wp-content\/uploads\/2019\/11\/codemotionlogo.png","contentUrl":"https:\/\/www.codemotion.com\/magazine\/wp-content\/uploads\/2019\/11\/codemotionlogo.png","width":225,"height":225,"caption":"Codemotion"},"image":{"@id":"https:\/\/www.codemotion.com\/magazine\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/Codemotion.Italy\/","https:\/\/x.com\/CodemotionIT"]},{"@type":"Person","@id":"https:\/\/www.codemotion.com\/magazine\/#\/schema\/person\/98d2abaf70e7d106abab1f38bf20f90d","name":"Federico Trotta","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/secure.gravatar.com\/avatar\/69bc8655986054bfe43c7eaa7f00e2ea939b761bd924064ea9b5972568a01714?s=96&d=mm&r=g","url":"https:\/\/secure.gravatar.com\/avatar\/69bc8655986054bfe43c7eaa7f00e2ea939b761bd924064ea9b5972568a01714?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/69bc8655986054bfe43c7eaa7f00e2ea939b761bd924064ea9b5972568a01714?s=96&d=mm&r=g","caption":"Federico Trotta"},"description":"I have loved writing since I was a young boy in school, writing detective stories as class exams. Thanks to my curiosity, I discovered programming and AI. Having a burning passion for writing, I couldn't avoid starting to write about these topics, so I decided to change my career to become a Technical Writer. My purpose is to educate people on Python programming, Machine Learning, and Data Science, through writing.","sameAs":["https:\/\/federicotrotta.com\/","https:\/\/www.linkedin.com\/in\/federico-trotta\/?originalSubdomain=it"],"url":"https:\/\/www.codemotion.com\/magazine\/author\/federico-trotta\/"}]}},"featured_image_src":"https:\/\/www.codemotion.com\/magazine\/wp-content\/uploads\/2023\/07\/iStock-1141236448-min-600x400.jpg","featured_image_src_square":"https:\/\/www.codemotion.com\/magazine\/wp-content\/uploads\/2023\/07\/iStock-1141236448-min-600x600.jpg","author_info":{"display_name":"Federico Trotta","author_link":"https:\/\/www.codemotion.com\/magazine\/author\/federico-trotta\/"},"uagb_featured_image_src":{"full":["https:\/\/www.codemotion.com\/magazine\/wp-content\/uploads\/2023\/07\/iStock-1141236448-min.jpg",1183,887,false],"thumbnail":["https:\/\/www.codemotion.com\/magazine\/wp-content\/uploads\/2023\/07\/iStock-1141236448-min-150x150.jpg",150,150,true],"medium":["https:\/\/www.codemotion.com\/magazine\/wp-content\/uploads\/2023\/07\/iStock-1141236448-min-300x225.jpg",300,225,true],"medium_large":["https:\/\/www.codemotion.com\/magazine\/wp-content\/uploads\/2023\/07\/iStock-1141236448-min-768x576.jpg",768,576,true],"large":["https:\/\/www.codemotion.com\/magazine\/wp-content\/uploads\/2023\/07\/iStock-1141236448-min-1024x768.jpg",1024,768,true],"1536x1536":["https:\/\/www.codemotion.com\/magazine\/wp-content\/uploads\/2023\/07\/iStock-1141236448-min.jpg",1183,887,false],"2048x2048":["https:\/\/www.codemotion.com\/magazine\/wp-content\/uploads\/2023\/07\/iStock-1141236448-min.jpg",1183,887,false],"small-home-featured":["https:\/\/www.codemotion.com\/magazine\/wp-content\/uploads\/2023\/07\/iStock-1141236448-min.jpg",100,75,false],"sidebar-featured":["https:\/\/www.codemotion.com\/magazine\/wp-content\/uploads\/2023\/07\/iStock-1141236448-min-180x128.jpg",180,128,true],"genesis-singular-images":["https:\/\/www.codemotion.com\/magazine\/wp-content\/uploads\/2023\/07\/iStock-1141236448-min-896x504.jpg",896,504,true],"archive-featured":["https:\/\/www.codemotion.com\/magazine\/wp-content\/uploads\/2023\/07\/iStock-1141236448-min-400x225.jpg",400,225,true],"gb-block-post-grid-landscape":["https:\/\/www.codemotion.com\/magazine\/wp-content\/uploads\/2023\/07\/iStock-1141236448-min-600x400.jpg",600,400,true],"gb-block-post-grid-square":["https:\/\/www.codemotion.com\/magazine\/wp-content\/uploads\/2023\/07\/iStock-1141236448-min-600x600.jpg",600,600,true]},"uagb_author_info":{"display_name":"Federico Trotta","author_link":"https:\/\/www.codemotion.com\/magazine\/author\/federico-trotta\/"},"uagb_comment_info":0,"uagb_excerpt":"When talking about data analysis, Pandas is surely the most powerful and widely used Python library for data manipulation, cleaning, and preprocessing. Thanks to its features, in fact, we can work with tabular data, retrieving them from SQL databases or Excel spreadsheets, for example. Then, we have the possibility to manipulate and clean the data&#8230;&hellip;","lang":"en","_links":{"self":[{"href":"https:\/\/www.codemotion.com\/magazine\/wp-json\/wp\/v2\/posts\/22040","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.codemotion.com\/magazine\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.codemotion.com\/magazine\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.codemotion.com\/magazine\/wp-json\/wp\/v2\/users\/171"}],"replies":[{"embeddable":true,"href":"https:\/\/www.codemotion.com\/magazine\/wp-json\/wp\/v2\/comments?post=22040"}],"version-history":[{"count":1,"href":"https:\/\/www.codemotion.com\/magazine\/wp-json\/wp\/v2\/posts\/22040\/revisions"}],"predecessor-version":[{"id":22041,"href":"https:\/\/www.codemotion.com\/magazine\/wp-json\/wp\/v2\/posts\/22040\/revisions\/22041"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.codemotion.com\/magazine\/wp-json\/wp\/v2\/media\/21978"}],"wp:attachment":[{"href":"https:\/\/www.codemotion.com\/magazine\/wp-json\/wp\/v2\/media?parent=22040"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.codemotion.com\/magazine\/wp-json\/wp\/v2\/categories?post=22040"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.codemotion.com\/magazine\/wp-json\/wp\/v2\/tags?post=22040"},{"taxonomy":"collections","embeddable":true,"href":"https:\/\/www.codemotion.com\/magazine\/wp-json\/wp\/v2\/collections?post=22040"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}