{"id":5665,"date":"2021-01-01T13:27:18","date_gmt":"2021-01-01T07:57:18","guid":{"rendered":"https:\/\/copyassignment.com\/?p=5665"},"modified":"2022-08-01T17:29:52","modified_gmt":"2022-08-01T11:59:52","slug":"python-pandas-tutorial-complete-introduction","status":"publish","type":"post","link":"https:\/\/copyassignment.com\/python-pandas-tutorial-complete-introduction\/","title":{"rendered":"Python Pandas Tutorial: A Complete Introduction for Beginners"},"content":{"rendered":"\n<p>In the previous section, we learned about Numpy and how we can use it to load, save, and pre-process data easily by using Numpy Arrays. Now Numpy is a great library to do data preprocessing but I&#8217;d like to tell you all about another wonderful Python library called <strong>Pandas<\/strong>.<\/p>\n\n\n\n<p>At the end of this tutorial, I have a bonus topic for you all which is quite rare but might come in pretty handy during the presentation. Spoiler Alert: It&#8217;s on Styling in Pandas.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Introducing Pandas<\/h2>\n\n\n\n<p>Pandas is a library that is built on top of NumPy. It offers several data structures that have a wide range of functionalities, which makes data analysis easier. We&#8217;ll talk about these Data Structures soon. It&#8217;s important that you know about NumPy, if you don&#8217;t you can learn about it <a href=\"https:\/\/copyassignment.com\/numpy-for-machine-learning-a-complete-guide\/\" class=\"rank-math-link\"><strong>here.<\/strong><\/a><\/p>\n\n\n\n<p>Apart from that, we&#8217;ll be doing data analysis over a real dataset. Yay!<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">What is a Series in Python Pandas?<\/h2>\n\n\n\n<script async=\"\" src=\"https:\/\/pagead2.googlesyndication.com\/pagead\/js\/adsbygoogle.js\"><\/script>\n<ins class=\"adsbygoogle\" style=\"display:block; text-align:center;\" data-ad-layout=\"in-article\" data-ad-format=\"fluid\" data-ad-client=\"ca-pub-9886351916045880\" data-ad-slot=\"2002566052\"><\/ins>\n<script>\n     (adsbygoogle = window.adsbygoogle || []).push({});\n<\/script>\n\n\n\n<p>Pandas contain Series which are the building blocks for the primary data structure in pandas i.e. DataFrames. Series are a 1-d array that has an index column and a label attached to it, along with other functionalities. You can think of a Series as a column in a spreadsheet. Let&#8217;s take a look at how you can create them.<\/p>\n\n\n\n<p>Let&#8217;s start by importing pandas. Conventionally, we use <strong>pd<\/strong> as an alias for pandas.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">import pandas as pd<\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">Creating Series in Pandas<\/h3>\n\n\n\n<p>To start with Pandas, let&#8217;s take an example by creating a Series using the list.  To do so, you just have to pass the list to pd.Series() <\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img decoding=\"async\" width=\"428\" height=\"413\" data-src=\"https:\/\/copyassignment.com\/wp-content\/uploads\/2022\/08\/a.png\" alt=\"creating series in python pandas\" class=\"wp-image-15704 lazyload\" data-srcset=\"https:\/\/copyassignment.com\/wp-content\/uploads\/2022\/08\/a.png 428w, https:\/\/copyassignment.com\/wp-content\/uploads\/2022\/08\/a-300x289.png 300w\" data-sizes=\"(max-width: 428px) 100vw, 428px\" src=\"data:image\/svg+xml;base64,PHN2ZyB3aWR0aD0iMSIgaGVpZ2h0PSIxIiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciPjwvc3ZnPg==\" style=\"--smush-placeholder-width: 428px; --smush-placeholder-aspect-ratio: 428\/413;\" \/><figcaption>Creating series in Python Pandas<\/figcaption><\/figure>\n\n\n\n<p>As you can in the above picture we created a list of numbers from 2 to 100 in reverse order and passed it pd.Series(), which created a series for it. The series output was 2 columns, the first one is an <strong>index column<\/strong> and the second one is the column that has the values of the list, along with the type and length of the series. One thing to note is that we didn&#8217;t require to print the series using <strong>print()<\/strong> to get an output. <\/p>\n\n\n\n<p>It&#8217;s because in a jupyter cell the output of the object in the last line will be printed. Since in the last line of this cell we had our series object, its value was printed.<\/p>\n\n\n\n<p>Now that we created a series using a list we can do it the same way for the NumPy array.<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img decoding=\"async\" width=\"384\" height=\"314\" data-src=\"https:\/\/copyassignment.com\/wp-content\/uploads\/2022\/08\/b.png\" alt=\"creating similar series with numpy\" class=\"wp-image-15705 lazyload\" data-srcset=\"https:\/\/copyassignment.com\/wp-content\/uploads\/2022\/08\/b.png 384w, https:\/\/copyassignment.com\/wp-content\/uploads\/2022\/08\/b-300x245.png 300w\" data-sizes=\"(max-width: 384px) 100vw, 384px\" src=\"data:image\/svg+xml;base64,PHN2ZyB3aWR0aD0iMSIgaGVpZ2h0PSIxIiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciPjwvc3ZnPg==\" style=\"--smush-placeholder-width: 384px; --smush-placeholder-aspect-ratio: 384\/314;\" \/><figcaption>Creating similar series with numpy<\/figcaption><\/figure>\n\n\n\n<p>And as you can see we got a similar result. Now that we are familiar with how to create a series. Let&#8217;s take a look at how you can use one of its functionalities called <strong>apply()<\/strong>. What apply() does is that it takes in a function and applies it over each element and replaces the element with what the function returns. Let&#8217;s see how you can do it.<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img decoding=\"async\" width=\"399\" height=\"478\" data-src=\"https:\/\/copyassignment.com\/wp-content\/uploads\/2022\/08\/c.png\" alt=\"filtering series values by applying a function to pandas series\" class=\"wp-image-15706 lazyload\" data-srcset=\"https:\/\/copyassignment.com\/wp-content\/uploads\/2022\/08\/c.png 399w, https:\/\/copyassignment.com\/wp-content\/uploads\/2022\/08\/c-250x300.png 250w\" data-sizes=\"(max-width: 399px) 100vw, 399px\" src=\"data:image\/svg+xml;base64,PHN2ZyB3aWR0aD0iMSIgaGVpZ2h0PSIxIiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciPjwvc3ZnPg==\" style=\"--smush-placeholder-width: 399px; --smush-placeholder-aspect-ratio: 399\/478;\" \/><figcaption>Filtering series values by applying a function to pandas series<\/figcaption><\/figure>\n\n\n\n<p>As you can see the even elements were replaced with 1 and odd elements were replaced with 0. We passed the function in apply() as an argument, the function returns 1 if the element is even and 0 if the element is odd. Therefore, even elements were replaced with 1, and odd elements were replaced with 0. But apply() doesn&#8217;t change the series itself, instead, it returns a transformed series leaving the original one the same.<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img decoding=\"async\" width=\"410\" height=\"445\" data-src=\"https:\/\/copyassignment.com\/wp-content\/uploads\/2022\/08\/d.png\" alt=\"no changes in original series\" class=\"wp-image-15707 lazyload\" data-srcset=\"https:\/\/copyassignment.com\/wp-content\/uploads\/2022\/08\/d.png 410w, https:\/\/copyassignment.com\/wp-content\/uploads\/2022\/08\/d-276x300.png 276w\" data-sizes=\"(max-width: 410px) 100vw, 410px\" src=\"data:image\/svg+xml;base64,PHN2ZyB3aWR0aD0iMSIgaGVpZ2h0PSIxIiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciPjwvc3ZnPg==\" style=\"--smush-placeholder-width: 410px; --smush-placeholder-aspect-ratio: 410\/445;\" \/><figcaption>No changes in original series<\/figcaption><\/figure>\n\n\n\n<p>But if you wanna keep the changes in the original series you can do so by assigning the transformed series to the original series object:-<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img decoding=\"async\" width=\"438\" height=\"469\" data-src=\"https:\/\/copyassignment.com\/wp-content\/uploads\/2022\/08\/e.png\" alt=\"storing original series\" class=\"wp-image-15708 lazyload\" data-srcset=\"https:\/\/copyassignment.com\/wp-content\/uploads\/2022\/08\/e.png 438w, https:\/\/copyassignment.com\/wp-content\/uploads\/2022\/08\/e-280x300.png 280w\" data-sizes=\"(max-width: 438px) 100vw, 438px\" src=\"data:image\/svg+xml;base64,PHN2ZyB3aWR0aD0iMSIgaGVpZ2h0PSIxIiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciPjwvc3ZnPg==\" style=\"--smush-placeholder-width: 438px; --smush-placeholder-aspect-ratio: 438\/469;\" \/><figcaption>Storing original series<\/figcaption><\/figure>\n\n\n\n<p>We can also pass lambda functions as an argument and it&#8217;ll still work the same. If you don&#8217;t know about ternary operators you can read about them <a href=\"https:\/\/www.tutorialspoint.com\/ternary-operator-in-python\" target=\"_blank\" rel=\"noreferrer noopener\">here.<\/a><\/p>\n\n\n\n<h2 class=\"wp-block-heading\">DataFrames in Pandas in Python<\/h2>\n\n\n\n<script async=\"\" src=\"https:\/\/pagead2.googlesyndication.com\/pagead\/js\/adsbygoogle.js\"><\/script>\n<ins class=\"adsbygoogle\" style=\"display:block; text-align:center;\" data-ad-layout=\"in-article\" data-ad-format=\"fluid\" data-ad-client=\"ca-pub-9886351916045880\" data-ad-slot=\"2002566052\"><\/ins>\n<script>\n     (adsbygoogle = window.adsbygoogle || []).push({});\n<\/script>\n\n\n\n<p>If Pandas Series is a column of the spreadsheet, then DataFrames are the spreadsheet itself. DataFrame behaves the same way as an excel file. They have an index for corresponding rows and a label for each column. <\/p>\n\n\n\n<p>Dataframes offer a long variety of functions that make data analysis easier, for example, summary statistics, column details, etc. We&#8217;ll take a look at how all this happens but first, let&#8217;s talk about CSV files if you are learning Pandas, you will need to work with CSV files for sure.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">What is a CSV file?<\/h3>\n\n\n\n<p>CSV stands for <strong>Comma Separated<\/strong> <strong>Values<\/strong>. In a CSV file, the elements are separated by a <strong>&#8216;,&#8217;<\/strong>.  Pandas actually have a function <strong>read_csv()<\/strong> which you can use to easily load the contents of a CSV file into a data frame. Let&#8217;s see how.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Pandas DataFrame Operations<\/h3>\n\n\n\n<h4 class=\"wp-block-heading\">Loading CSV file into a DataFrame<\/h4>\n\n\n\n<figure class=\"wp-block-image size-full\"><img decoding=\"async\" width=\"408\" height=\"321\" data-src=\"https:\/\/copyassignment.com\/wp-content\/uploads\/2022\/08\/f.png\" alt=\"Loading CSV file into a pandas DataFrame\" class=\"wp-image-15710 lazyload\" data-srcset=\"https:\/\/copyassignment.com\/wp-content\/uploads\/2022\/08\/f.png 408w, https:\/\/copyassignment.com\/wp-content\/uploads\/2022\/08\/f-300x236.png 300w\" data-sizes=\"(max-width: 408px) 100vw, 408px\" src=\"data:image\/svg+xml;base64,PHN2ZyB3aWR0aD0iMSIgaGVpZ2h0PSIxIiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciPjwvc3ZnPg==\" style=\"--smush-placeholder-width: 408px; --smush-placeholder-aspect-ratio: 408\/321;\" \/><figcaption>Loading CSV file into a pandas DataFrame<\/figcaption><\/figure>\n\n\n\n<p>As you can see there are 2 columns. 1st column has the name x and 2nd column has the name y. In the data frame, you can get the values stored in each column individually by calling the columns by their name themselves.<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img decoding=\"async\" width=\"370\" height=\"298\" data-src=\"https:\/\/copyassignment.com\/wp-content\/uploads\/2022\/08\/g.png\" alt=\"printing a column of pandas dataframe in python\" class=\"wp-image-15713 lazyload\" data-srcset=\"https:\/\/copyassignment.com\/wp-content\/uploads\/2022\/08\/g.png 370w, https:\/\/copyassignment.com\/wp-content\/uploads\/2022\/08\/g-300x242.png 300w\" data-sizes=\"(max-width: 370px) 100vw, 370px\" src=\"data:image\/svg+xml;base64,PHN2ZyB3aWR0aD0iMSIgaGVpZ2h0PSIxIiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciPjwvc3ZnPg==\" style=\"--smush-placeholder-width: 370px; --smush-placeholder-aspect-ratio: 370\/298;\" \/><figcaption>printing a column of pandas dataframe in python<\/figcaption><\/figure>\n\n\n\n<p>Now one last thing, earlier I said that if a series is a column then the data frame is a spreadsheet. Does that mean that DataFrames are a collection of series? Short answer, Yes. Every single column in DataFrame is a Series.<\/p>\n\n\n\n<h4 class=\"wp-block-heading\">Adding a column in DataFrame in Python Pandas<\/h4>\n\n\n\n<p>Adding a column in Dataframe is as easy as declaring a variable. Just call the name of the new column via the data frame and assign it a value. You can also create new columns that&#8217;ll have the values of the results of operation between the 2 columns. Let&#8217;s create a column <strong>&#8216;sum_x_y&#8217;<\/strong> that has values obtained by adding each element of column x with the corresponding value in column y.<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img decoding=\"async\" width=\"423\" height=\"325\" data-src=\"https:\/\/copyassignment.com\/wp-content\/uploads\/2022\/08\/h.png\" alt=\"Adding a column in DataFrame in Python Pandas\" class=\"wp-image-15714 lazyload\" data-srcset=\"https:\/\/copyassignment.com\/wp-content\/uploads\/2022\/08\/h.png 423w, https:\/\/copyassignment.com\/wp-content\/uploads\/2022\/08\/h-300x230.png 300w\" data-sizes=\"(max-width: 423px) 100vw, 423px\" src=\"data:image\/svg+xml;base64,PHN2ZyB3aWR0aD0iMSIgaGVpZ2h0PSIxIiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciPjwvc3ZnPg==\" style=\"--smush-placeholder-width: 423px; --smush-placeholder-aspect-ratio: 423\/325;\" \/><figcaption>Adding a column in DataFrame in Python Pandas<\/figcaption><\/figure>\n\n\n\n<p>Let&#8217;s add another column that&#8217;ll have a cube of elements in column x.<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img decoding=\"async\" width=\"420\" height=\"299\" data-src=\"https:\/\/copyassignment.com\/wp-content\/uploads\/2022\/08\/i.png\" alt=\"Adding one more column to Pandas  DataFrame in Python\" class=\"wp-image-15715 lazyload\" data-srcset=\"https:\/\/copyassignment.com\/wp-content\/uploads\/2022\/08\/i.png 420w, https:\/\/copyassignment.com\/wp-content\/uploads\/2022\/08\/i-300x214.png 300w\" data-sizes=\"(max-width: 420px) 100vw, 420px\" src=\"data:image\/svg+xml;base64,PHN2ZyB3aWR0aD0iMSIgaGVpZ2h0PSIxIiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciPjwvc3ZnPg==\" style=\"--smush-placeholder-width: 420px; --smush-placeholder-aspect-ratio: 420\/299;\" \/><figcaption>Adding one more column to Pandas DataFrame in Python<\/figcaption><\/figure>\n\n\n\n<h4 class=\"wp-block-heading\"><strong>Deleting a Column<\/strong> in Pandas DataFrame<\/h4>\n\n\n\n<p>Deleting a column in a data frame can be done using the <strong>del<\/strong> <strong>keyword <\/strong>or <strong>drop() function<\/strong>. Let&#8217;s see how you can delete a row using <strong>del<\/strong>. <\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img decoding=\"async\" width=\"316\" height=\"259\" data-src=\"https:\/\/copyassignment.com\/wp-content\/uploads\/2022\/08\/j.png\" alt=\"Deleting a Column in Pandas DataFrame using the del keyword\" class=\"wp-image-15716 lazyload\" data-srcset=\"https:\/\/copyassignment.com\/wp-content\/uploads\/2022\/08\/j.png 316w, https:\/\/copyassignment.com\/wp-content\/uploads\/2022\/08\/j-300x246.png 300w\" data-sizes=\"(max-width: 316px) 100vw, 316px\" src=\"data:image\/svg+xml;base64,PHN2ZyB3aWR0aD0iMSIgaGVpZ2h0PSIxIiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciPjwvc3ZnPg==\" style=\"--smush-placeholder-width: 316px; --smush-placeholder-aspect-ratio: 316\/259;\" \/><figcaption><strong>Deleting a Column in Pandas DataFrame using the del keyword<\/strong><\/figcaption><\/figure>\n\n\n\n<p>As you can see the deletion was <b>inplace<\/b> and changes were reflected in the original data frame. Now let&#8217;s see how you can delete a column using <strong>drop().<\/strong><\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img decoding=\"async\" width=\"348\" height=\"257\" data-src=\"https:\/\/copyassignment.com\/wp-content\/uploads\/2022\/08\/k.png\" alt=\"Deleting a Column in Pandas DataFrame using the drop() method\" class=\"wp-image-15717 lazyload\" data-srcset=\"https:\/\/copyassignment.com\/wp-content\/uploads\/2022\/08\/k.png 348w, https:\/\/copyassignment.com\/wp-content\/uploads\/2022\/08\/k-300x222.png 300w\" data-sizes=\"(max-width: 348px) 100vw, 348px\" src=\"data:image\/svg+xml;base64,PHN2ZyB3aWR0aD0iMSIgaGVpZ2h0PSIxIiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciPjwvc3ZnPg==\" style=\"--smush-placeholder-width: 348px; --smush-placeholder-aspect-ratio: 348\/257;\" \/><figcaption>Deleting a Column in Pandas DataFrame using the drop() method<\/figcaption><\/figure>\n\n\n\n<p>As you might have figured out drop() doesn&#8217;t do the changes in the data frame itself, rather it returns a transformed data frame but doesn&#8217;t change the original data frame. We used axis = 1 to tell that the element to be deleted is across the column. <\/p>\n\n\n\n<p>In order to do the changes in the original data frame itself, you can pass another argument <strong>inplace = True<\/strong>. You can also delete multiple columns at the same time bypassing the list of columns.<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img decoding=\"async\" width=\"390\" height=\"259\" data-src=\"https:\/\/copyassignment.com\/wp-content\/uploads\/2022\/08\/l.png\" alt=\"Deleting multiple Columns in Pandas DataFrame using the drop() method\" class=\"wp-image-15718 lazyload\" data-srcset=\"https:\/\/copyassignment.com\/wp-content\/uploads\/2022\/08\/l.png 390w, https:\/\/copyassignment.com\/wp-content\/uploads\/2022\/08\/l-300x199.png 300w\" data-sizes=\"(max-width: 390px) 100vw, 390px\" src=\"data:image\/svg+xml;base64,PHN2ZyB3aWR0aD0iMSIgaGVpZ2h0PSIxIiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciPjwvc3ZnPg==\" style=\"--smush-placeholder-width: 390px; --smush-placeholder-aspect-ratio: 390\/259;\" \/><figcaption>Deleting multiple Columns in Pandas DataFrame using the drop() method<\/figcaption><\/figure>\n\n\n\n<h4 class=\"wp-block-heading\">Selecting Data based on a Condition<\/h4>\n\n\n\n<p>Like np array&#8217;s boolean indexing you can select rows in a data frame based on a condition.<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img decoding=\"async\" width=\"349\" height=\"201\" data-src=\"https:\/\/copyassignment.com\/wp-content\/uploads\/2022\/08\/n.png\" alt=\"Selecting Data based on a Condition\" class=\"wp-image-15689 lazyload\" data-srcset=\"https:\/\/copyassignment.com\/wp-content\/uploads\/2022\/08\/n.png 349w, https:\/\/copyassignment.com\/wp-content\/uploads\/2022\/08\/n-300x173.png 300w\" data-sizes=\"(max-width: 349px) 100vw, 349px\" src=\"data:image\/svg+xml;base64,PHN2ZyB3aWR0aD0iMSIgaGVpZ2h0PSIxIiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciPjwvc3ZnPg==\" style=\"--smush-placeholder-width: 349px; --smush-placeholder-aspect-ratio: 349\/201;\" \/><figcaption>Selecting Data based on a Condition<\/figcaption><\/figure>\n\n\n\n<p>And like that, you can select rows based on a condition. Applying relational operators over a data frame created a boolean series that contains a bool value signifying whether the rows fulfill the condition or not. Passing it to the data frame will return a data frame with rows that follow that condition.<\/p>\n\n\n\n<h4 class=\"wp-block-heading\">iloc method<\/h4>\n\n\n\n<p><strong>iloc method<\/strong> can be used for slicing data frames. Slicing works the same way as it did in NumPy.<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img decoding=\"async\" width=\"349\" height=\"180\" data-src=\"https:\/\/copyassignment.com\/wp-content\/uploads\/2022\/08\/o.png\" alt=\"iloc method for slicing data frames in pandas\" class=\"wp-image-15690 lazyload\" data-srcset=\"https:\/\/copyassignment.com\/wp-content\/uploads\/2022\/08\/o.png 349w, https:\/\/copyassignment.com\/wp-content\/uploads\/2022\/08\/o-300x155.png 300w\" data-sizes=\"(max-width: 349px) 100vw, 349px\" src=\"data:image\/svg+xml;base64,PHN2ZyB3aWR0aD0iMSIgaGVpZ2h0PSIxIiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciPjwvc3ZnPg==\" style=\"--smush-placeholder-width: 349px; --smush-placeholder-aspect-ratio: 349\/180;\" \/><figcaption>iloc method for slicing data frames in pandas<\/figcaption><\/figure>\n\n\n\n<h4 class=\"wp-block-heading\">Changing dtype and names of a columns<\/h4>\n\n\n\n<p>Let&#8217;s start by creating our data frame. Now that we have our data frame. Let&#8217;s check the dtype of <strong>columns.<\/strong><\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img decoding=\"async\" width=\"409\" height=\"185\" data-src=\"https:\/\/copyassignment.com\/wp-content\/uploads\/2022\/08\/p.png\" alt=\"Changing dtype and names of columns in Python Pandas\" class=\"wp-image-15691 lazyload\" data-srcset=\"https:\/\/copyassignment.com\/wp-content\/uploads\/2022\/08\/p.png 409w, https:\/\/copyassignment.com\/wp-content\/uploads\/2022\/08\/p-300x136.png 300w\" data-sizes=\"(max-width: 409px) 100vw, 409px\" src=\"data:image\/svg+xml;base64,PHN2ZyB3aWR0aD0iMSIgaGVpZ2h0PSIxIiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciPjwvc3ZnPg==\" style=\"--smush-placeholder-width: 409px; --smush-placeholder-aspect-ratio: 409\/185;\" \/><figcaption>Changing dtype and names of columns in Python Pandas<\/figcaption><\/figure>\n\n\n\n<p>As seen the dtype of the column is int. We can change it to string or any other datatype using astype() method. Let&#8217;s see how.<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img decoding=\"async\" width=\"360\" height=\"148\" data-src=\"https:\/\/copyassignment.com\/wp-content\/uploads\/2022\/08\/q.png\" alt=\"change to string\" class=\"wp-image-15692 lazyload\" data-srcset=\"https:\/\/copyassignment.com\/wp-content\/uploads\/2022\/08\/q.png 360w, https:\/\/copyassignment.com\/wp-content\/uploads\/2022\/08\/q-300x123.png 300w\" data-sizes=\"(max-width: 360px) 100vw, 360px\" src=\"data:image\/svg+xml;base64,PHN2ZyB3aWR0aD0iMSIgaGVpZ2h0PSIxIiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciPjwvc3ZnPg==\" style=\"--smush-placeholder-width: 360px; --smush-placeholder-aspect-ratio: 360\/148;\" \/><figcaption>Change to String<\/figcaption><\/figure>\n\n\n\n<h4 class=\"wp-block-heading\">Saving a DataFrame as CSV File<\/h4>\n\n\n\n<p>You can save Pandas dataframes as CSV files to using the method <strong>to_csv()<\/strong>.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">demo.to_csv('demo.csv')<\/pre>\n\n\n\n<p>We can actually convert dataframes to various other formal using <strong>to_numpy()<\/strong>, <strong>to_list()<\/strong> etc.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Data analysis using Python Pandas: A Practical Example<\/h2>\n\n\n\n<script async=\"\" src=\"https:\/\/pagead2.googlesyndication.com\/pagead\/js\/adsbygoogle.js\"><\/script>\n<ins class=\"adsbygoogle\" style=\"display:block; text-align:center;\" data-ad-layout=\"in-article\" data-ad-format=\"fluid\" data-ad-client=\"ca-pub-9886351916045880\" data-ad-slot=\"2002566052\"><\/ins>\n<script>\n     (adsbygoogle = window.adsbygoogle || []).push({});\n<\/script>\n\n\n\n<p>Now let&#8217;s get our hands dirty with some real-life data analysis to dive deep into the world of Pandas. For that, I&#8217;ll be using the <strong><a href=\"https:\/\/www.kaggle.com\/c\/titanic\" target=\"_blank\" rel=\"noreferrer noopener\">Titanic Dataset.<\/a><\/strong> Let&#8217;s start by loading our data. <\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img decoding=\"async\" width=\"331\" height=\"289\" data-src=\"https:\/\/copyassignment.com\/wp-content\/uploads\/2022\/08\/r-1.png\" alt=\"importing dataset for data analysis in Pandas\" class=\"wp-image-15694 lazyload\" data-srcset=\"https:\/\/copyassignment.com\/wp-content\/uploads\/2022\/08\/r-1.png 331w, https:\/\/copyassignment.com\/wp-content\/uploads\/2022\/08\/r-1-300x262.png 300w\" data-sizes=\"(max-width: 331px) 100vw, 331px\" src=\"data:image\/svg+xml;base64,PHN2ZyB3aWR0aD0iMSIgaGVpZ2h0PSIxIiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciPjwvc3ZnPg==\" style=\"--smush-placeholder-width: 331px; --smush-placeholder-aspect-ratio: 331\/289;\" \/><figcaption>importing dataset for data analysis in Pandas<\/figcaption><\/figure>\n\n\n\n<p>So as you can see we loaded our data using <strong>read_csv()<\/strong> and displayed the first <strong>10 rows<\/strong> by using <strong>head()<\/strong>, the number passed as an argument in the head() is the number of rows that will be printed from the top. The default number of rows for the head() is 5.<\/p>\n\n\n\n<p>In order to look at the n rows from the bottom, you can use the <strong>tail()<\/strong> method. <\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img decoding=\"async\" width=\"438\" height=\"218\" data-src=\"https:\/\/copyassignment.com\/wp-content\/uploads\/2022\/08\/s.png\" alt=\"tail() method to look for bottom values in Pandas\" class=\"wp-image-15695 lazyload\" data-srcset=\"https:\/\/copyassignment.com\/wp-content\/uploads\/2022\/08\/s.png 438w, https:\/\/copyassignment.com\/wp-content\/uploads\/2022\/08\/s-300x149.png 300w\" data-sizes=\"(max-width: 438px) 100vw, 438px\" src=\"data:image\/svg+xml;base64,PHN2ZyB3aWR0aD0iMSIgaGVpZ2h0PSIxIiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciPjwvc3ZnPg==\" style=\"--smush-placeholder-width: 438px; --smush-placeholder-aspect-ratio: 438\/218;\" \/><figcaption>tail() method to look for bottom values in Pandas<\/figcaption><\/figure>\n\n\n\n<p>And as you can see it shows that the last 5 rows were displayed and one more thing to notice is the first column, marked with an arrow, with bolded no. this column is called the <strong>index column<\/strong> and you can customize this too. <\/p>\n\n\n\n<p>Won&#8217;t it be more appropriate for our PassengerID to be the index column? Let&#8217;s try making it the index column.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Creating Custom Index Column<\/h3>\n\n\n\n<h4 class=\"wp-block-heading\">Method 1: Using the set_index method<\/h4>\n\n\n\n<p>We can change the index column by passing the name of the new index column as an argument to the set_index() method. <\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img decoding=\"async\" width=\"383\" height=\"264\" data-src=\"https:\/\/copyassignment.com\/wp-content\/uploads\/2022\/08\/t.png\" alt=\"Creating Custom Index Column in Pandas in Python Using the set_index method\" class=\"wp-image-15697 lazyload\" data-srcset=\"https:\/\/copyassignment.com\/wp-content\/uploads\/2022\/08\/t.png 383w, https:\/\/copyassignment.com\/wp-content\/uploads\/2022\/08\/t-300x207.png 300w\" data-sizes=\"(max-width: 383px) 100vw, 383px\" src=\"data:image\/svg+xml;base64,PHN2ZyB3aWR0aD0iMSIgaGVpZ2h0PSIxIiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciPjwvc3ZnPg==\" style=\"--smush-placeholder-width: 383px; --smush-placeholder-aspect-ratio: 383\/264;\" \/><figcaption>Creating Custom Index Column in Pandas in Python Using the set_index method<\/figcaption><\/figure>\n\n\n\n<p>And you can actually create multiple index columns.<\/p>\n\n\n\n<h4 class=\"wp-block-heading\">Method 2: By Passing column name as an argument<\/h4>\n\n\n\n<p>Apart from the method above, you can also pass the name of columns you wanna make an index in form of a list to the <strong>index_col<\/strong> argument in the function <strong>pd.read_csv()<\/strong>. <\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img decoding=\"async\" width=\"574\" height=\"330\" data-src=\"https:\/\/copyassignment.com\/wp-content\/uploads\/2022\/08\/u.png\" alt=\"Creating Custom Index Column in Pandas in Python By Passing column name as an argument\" class=\"wp-image-15698 lazyload\" data-srcset=\"https:\/\/copyassignment.com\/wp-content\/uploads\/2022\/08\/u.png 574w, https:\/\/copyassignment.com\/wp-content\/uploads\/2022\/08\/u-300x172.png 300w\" data-sizes=\"(max-width: 574px) 100vw, 574px\" src=\"data:image\/svg+xml;base64,PHN2ZyB3aWR0aD0iMSIgaGVpZ2h0PSIxIiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciPjwvc3ZnPg==\" style=\"--smush-placeholder-width: 574px; --smush-placeholder-aspect-ratio: 574\/330;\" \/><figcaption>Creating Custom Index Column in Pandas in Python By Passing column name as an argument<\/figcaption><\/figure>\n\n\n\n<h3 class=\"wp-block-heading\">Data Exploration<\/h3>\n\n\n\n<p>Now that we know how to load the data we should understand the data. Understanding what the data is and what it interprets plays an important role in data science and before preprocessing the dataset one must understand the dataset. And that&#8217;s what data exploration is all about.<\/p>\n\n\n\n<h4 class=\"wp-block-heading\">Shape of Data<\/h4>\n\n\n\n<p>Before starting any sort of exploration or cleaning it is better to understand the basic layout of data and by that I mean no. of rows and columns in the dataset. Let&#8217;s see how you can find it and how to interpret it.<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img decoding=\"async\" width=\"238\" height=\"71\" data-src=\"https:\/\/copyassignment.com\/wp-content\/uploads\/2022\/08\/v.png\" alt=\"shape of data in Pandas\" class=\"wp-image-15699 lazyload\" src=\"data:image\/svg+xml;base64,PHN2ZyB3aWR0aD0iMSIgaGVpZ2h0PSIxIiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciPjwvc3ZnPg==\" style=\"--smush-placeholder-width: 238px; --smush-placeholder-aspect-ratio: 238\/71;\" \/><\/figure>\n\n\n\n<p>We received a tuple with 2 values. The first value is the <strong>no. of rows<\/strong> and the second value is the <strong>no. of columns<\/strong>. So as seen in the image the no. of entries is 891 and the no. of features is 12. <\/p>\n\n\n\n<h4 class=\"wp-block-heading\">Fetching Column Info<\/h4>\n\n\n\n<p>Now that we know the basic layout of the data let&#8217;s understand it in a bit more detail. So the next thing to do is to get a basic idea about the features in your dataset like if any column has any missing value and the dtype of the features. To get that we use the <strong>info()<\/strong> method.<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img decoding=\"async\" width=\"508\" height=\"210\" data-src=\"https:\/\/copyassignment.com\/wp-content\/uploads\/2022\/08\/w.png\" alt=\"fetching column information in Python Pandas\" class=\"wp-image-15700 lazyload\" data-srcset=\"https:\/\/copyassignment.com\/wp-content\/uploads\/2022\/08\/w.png 508w, https:\/\/copyassignment.com\/wp-content\/uploads\/2022\/08\/w-300x124.png 300w\" data-sizes=\"(max-width: 508px) 100vw, 508px\" src=\"data:image\/svg+xml;base64,PHN2ZyB3aWR0aD0iMSIgaGVpZ2h0PSIxIiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciPjwvc3ZnPg==\" style=\"--smush-placeholder-width: 508px; --smush-placeholder-aspect-ratio: 508\/210;\" \/><figcaption>fetching column information in Python Pandas<\/figcaption><\/figure>\n\n\n\n<p><strong>info()<\/strong> method is used to get the summary of the dataframe. Let&#8217;s understand its output with the above image as an example:-<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li><strong>Total Entry and Index Range(Blue Arrow):<\/strong> Tells the no. of entries in the data set along with the first entry of the index column in this case 0 and the last entry of the index column in this case <strong>1<\/strong>. <\/li><li><strong>Feature Name:<\/strong> Among the 4 rows, the 1st column is Serial No. columns and the 2nd column is the column that contains the names of our features in the dataset.<\/li><li><strong>No. of Non-Null Rows(Dotted Rectangle):<\/strong>  This column contains the total no. of non-null entries in the corresponding feature. If this value is the same as the total no. of rows then there are no null values in the column else there are missing values.<\/li><li><strong>Dtype of the column(Purple Box):<\/strong> This column contains the dtype of the corresponding feature. You can go through this column and check if any column is of unsuitable dtype and change it to the correct one if necessary.<\/li><li><strong>Red Arrow:<\/strong> Summary about no. of columns having the corresponding type. This one has 2 float features, 5 int features, and 5 object features.<\/li><\/ul>\n\n\n\n<h4 class=\"wp-block-heading\">Fetching the Descriptive Statistics of the Dataset<\/h4>\n\n\n\n<p>Pandas provide us with mean(), median(), quartile(), etc. methods using which we can fetch the statistics of a dataset. But doing it for each column can be a tedious task. This is where the <strong>describe()<\/strong> method comes to the rescue. <\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img decoding=\"async\" width=\"377\" height=\"337\" data-src=\"https:\/\/copyassignment.com\/wp-content\/uploads\/2022\/08\/x.png\" alt=\"Fetching the Descriptive Statistics of the Dataset\" class=\"wp-image-15701 lazyload\" data-srcset=\"https:\/\/copyassignment.com\/wp-content\/uploads\/2022\/08\/x.png 377w, https:\/\/copyassignment.com\/wp-content\/uploads\/2022\/08\/x-300x268.png 300w\" data-sizes=\"(max-width: 377px) 100vw, 377px\" src=\"data:image\/svg+xml;base64,PHN2ZyB3aWR0aD0iMSIgaGVpZ2h0PSIxIiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciPjwvc3ZnPg==\" style=\"--smush-placeholder-width: 377px; --smush-placeholder-aspect-ratio: 377\/337;\" \/><\/figure>\n\n\n\n<p>This method provided us with the statistics for the numerical columns but we can also check statistics for categorical columns by passing argument <strong>include<\/strong> <strong>= &#8216;all&#8217;<\/strong>.<\/p>\n\n\n\n<p>Let&#8217;s understand the output:-<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li><strong>count:<\/strong> No. of non-null values.<\/li><li><strong>unique:<\/strong> No. of unique classes in a categorical column.<\/li><li><strong>top:<\/strong> Category with max frequency.<\/li><li><strong>freq: <\/strong>Frequency of the most frequent class.<\/li><li><strong>mean: <\/strong>Mean of the corresponding column.<\/li><li><strong>std: <\/strong>Standard Deviation of the corresponding column.<\/li><li><strong><strong>min:<\/strong><\/strong> Minimum Value in the corresponding column.<\/li><li><strong>25%,50%,75%:<\/strong> 1st,2nd(median),3rd Quartile of the corresponding column.   <\/li><li><strong>max:<\/strong> Maximum Value in the corresponding column.<\/li><\/ul>\n\n\n\n<h4 class=\"wp-block-heading\">No. of Classes and its frequency in a Categorical Column<\/h4>\n\n\n\n<p>When dealing with categorical columns you might want to know the classes it has and their frequency. For that, we can use:-<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img decoding=\"async\" width=\"379\" height=\"284\" data-src=\"https:\/\/copyassignment.com\/wp-content\/uploads\/2022\/08\/y.png\" alt=\"No. of Classes and its frequency in a Categorical Column\" class=\"wp-image-15702 lazyload\" data-srcset=\"https:\/\/copyassignment.com\/wp-content\/uploads\/2022\/08\/y.png 379w, https:\/\/copyassignment.com\/wp-content\/uploads\/2022\/08\/y-300x225.png 300w\" data-sizes=\"(max-width: 379px) 100vw, 379px\" src=\"data:image\/svg+xml;base64,PHN2ZyB3aWR0aD0iMSIgaGVpZ2h0PSIxIiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciPjwvc3ZnPg==\" style=\"--smush-placeholder-width: 379px; --smush-placeholder-aspect-ratio: 379\/284;\" \/><\/figure>\n\n\n\n<ul class=\"wp-block-list\"><li><strong>unique():<\/strong> This method returns all the classes that the column has including nan.<\/li><li><strong>nunique():<\/strong> This method returns the no. of classes that column has excluding nan.<\/li><li><strong>value_counts():<\/strong> This method returns the classes and their frequency in that column, excluding nan.<\/li><\/ul>\n\n\n\n<h3 class=\"wp-block-heading\">Data Cleaning in Python Using Pandas<\/h3>\n\n\n\n<h4 class=\"wp-block-heading\">Removing Useless Columns<\/h4>\n\n\n\n<p>Understanding which column is useful and which one isn&#8217;t is an important task that can be done in many ways. One of them is intuition. For example, in this dataset, we have to predict based on data if someone survived or not. <\/p>\n\n\n\n<h4 class=\"wp-block-heading\">Handling Missing Values in Pandas<\/h4>\n\n\n\n<p>Missing Values, also known as NaN values, is the result of an entry in a row that doesn&#8217;t exist. NaN stands for Not a Number. So how to find how many NaN or null values a column has? <\/p>\n\n\n\n<p>It&#8217;s simple we find which entries are null and assign a bool to it and then find the sum of that bool matrix along with the columns. That no. will be the no. of Null Values. <\/p>\n\n\n\n<p>As we can see Age has 177 NaN values and Embarked has 2 NaN values. Usually, ML models can fetch an error if trained on missing values, hence we usually tackle them by:-<\/p>\n\n\n\n<h5 class=\"wp-block-heading\">Dropping rows with NaN Values:-<\/h5>\n\n\n\n<p>One way to tackle NaN values is to remove the rows having NaN values from the dataset. If the column has a lot of NaN values we usually won&#8217;t take this approach. <\/p>\n\n\n\n<p>As you can see now the Embarked column now has no NaN values. Alternatively, you can use dropna() method on the column from which we wanna remove those entries.<\/p>\n\n\n\n<h5 class=\"wp-block-heading\">Replacing NaN Values with another Value<\/h5>\n\n\n\n<p>Age has 177 NaN values, so unlike Embarked, we can&#8217;t delete entries since it&#8217;ll result in the loss of a lot of information.<\/p>\n\n\n\n<p>Another way to tackle NaN values is to replace NaN with something else like mean, median, mode, etc. What to replace them with is a different topic but for now, let&#8217;s replace it with mean age using <strong>fillna()<\/strong> method. <\/p>\n\n\n\n<h4 class=\"wp-block-heading\">Handling String Values in Python Pandas<\/h4>\n\n\n\n<p>Usually, ML models need data to be strictly numerical thus any sort of string data can cause an error. Therefore we need to handle this by converting string data to numerical data. For this, we&#8217;ll create a function that&#8217;ll map the classes to an integer and use <strong>apply()<\/strong> to apply that function to all the elements.<\/p>\n\n\n\n<p>We have 2 columns with string values i.e. Embarked and Sex. Sex has 2 classes [&#8216;male&#8217;,&#8217;female&#8217;] who we&#8217;ll replace with [0,1] respectively.<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img decoding=\"async\" width=\"532\" height=\"338\" data-src=\"https:\/\/copyassignment.com\/wp-content\/uploads\/2021\/01\/image-13.png\" alt=\"Handling String Values in Python Pandas\" class=\"wp-image-5856 lazyload\" data-srcset=\"https:\/\/copyassignment.com\/wp-content\/uploads\/2021\/01\/image-13.png 532w, https:\/\/copyassignment.com\/wp-content\/uploads\/2021\/01\/image-13-300x191.png 300w\" data-sizes=\"(max-width: 532px) 100vw, 532px\" src=\"data:image\/svg+xml;base64,PHN2ZyB3aWR0aD0iMSIgaGVpZ2h0PSIxIiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciPjwvc3ZnPg==\" style=\"--smush-placeholder-width: 532px; --smush-placeholder-aspect-ratio: 532\/338;\" \/><\/figure>\n\n\n\n<p>Embarked has 3 classes [&#8216;S&#8217;,&#8217;C&#8217;,&#8217;Q&#8217;] who we&#8217;ll replace with [0,1,2] respectively.<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img decoding=\"async\" width=\"561\" height=\"375\" data-src=\"https:\/\/copyassignment.com\/wp-content\/uploads\/2021\/01\/image-14.png\" alt=\"distinguishing and Handling String Values in Python Pandas\" class=\"wp-image-5857 lazyload\" data-srcset=\"https:\/\/copyassignment.com\/wp-content\/uploads\/2021\/01\/image-14.png 561w, https:\/\/copyassignment.com\/wp-content\/uploads\/2021\/01\/image-14-300x201.png 300w\" data-sizes=\"(max-width: 561px) 100vw, 561px\" src=\"data:image\/svg+xml;base64,PHN2ZyB3aWR0aD0iMSIgaGVpZ2h0PSIxIiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciPjwvc3ZnPg==\" style=\"--smush-placeholder-width: 561px; --smush-placeholder-aspect-ratio: 561\/375;\" \/><\/figure>\n\n\n\n<p>Hooray! You just did your first data preprocessing task. Now There are many more things that are to be done and we&#8217;ll go into details about them but for now, this dataset is good enough to train a model.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Styling in Pandas<\/h2>\n\n\n\n<script async=\"\" src=\"https:\/\/pagead2.googlesyndication.com\/pagead\/js\/adsbygoogle.js\"><\/script>\n<ins class=\"adsbygoogle\" style=\"display:block; text-align:center;\" data-ad-layout=\"in-article\" data-ad-format=\"fluid\" data-ad-client=\"ca-pub-9886351916045880\" data-ad-slot=\"2002566052\"><\/ins>\n<script>\n     (adsbygoogle = window.adsbygoogle || []).push({});\n<\/script>\n\n\n\n<p>Time for the promised bonus topic. Now let&#8217;s suppose you wanna show the Age column in the format <strong>x year<\/strong> you can do that using format() method and specifying the display format for the corresponding column.<\/p>\n\n\n\n<p>If you don&#8217;t wanna show the index column you can use hide_index().<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img decoding=\"async\" width=\"474\" height=\"391\" data-src=\"https:\/\/copyassignment.com\/wp-content\/uploads\/2022\/08\/z.png\" alt=\"styling in pandas\" class=\"wp-image-15703 lazyload\" data-srcset=\"https:\/\/copyassignment.com\/wp-content\/uploads\/2022\/08\/z.png 474w, https:\/\/copyassignment.com\/wp-content\/uploads\/2022\/08\/z-300x247.png 300w\" data-sizes=\"(max-width: 474px) 100vw, 474px\" src=\"data:image\/svg+xml;base64,PHN2ZyB3aWR0aD0iMSIgaGVpZ2h0PSIxIiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciPjwvc3ZnPg==\" style=\"--smush-placeholder-width: 474px; --smush-placeholder-aspect-ratio: 474\/391;\" \/><figcaption>Styling in Pandas<\/figcaption><\/figure>\n\n\n\n<p>There many interesting things you can do with styling but that&#8217;s an article for another day. The aim was to introduce you to the concept of Styling in Pandas. Hopefully, you liked it and enjoyed it.<\/p>\n\n\n\n<p><strong>Thanks for Reading<\/strong><\/p>\n\n\n\n<p>Hope you enjoy our Python Pandas Tutorial and find it worth working on.<\/p>\n\n\n\n<p>Python Pandas Tutorial is part of our <strong><a href=\"https:\/\/copyassignment.com\/machine-learning-a-gentle-introduction\/\" class=\"rank-math-link\">Machine Learning Tutorial<\/a><\/strong>, take a look at the tutorial, if you are interested in Machine Learning.<\/p>\n\n\n\n<p>Tell us, if you found something wrong with this article.<\/p>\n\n\n\n<hr class=\"wp-block-separator has-css-opacity\"\/>\n\n\n\n<p style=\"font-size:26px\"><strong>Also Read:<\/strong><\/p>\n\n\n\n<hr class=\"wp-block-separator has-css-opacity\"\/>\n\n\n<ul class=\"wp-block-latest-posts__list wp-block-latest-posts\"><li><a class=\"wp-block-latest-posts__post-title\" href=\"https:\/\/copyassignment.com\/flower-classification-using-cnn\/\">Flower classification using CNN<\/a><div class=\"wp-block-latest-posts__post-excerpt\">You know how machine learning is developing and emerging daily to provide efficient and hurdle-free solutions to day-to-day problems. It covers all possible solutions, from building recommendation systems to predicting something. In this article, we are discussing one such machine-learning classification application i.e. Flower classification using CNN. We all come across a number of flowers&#8230;<\/div><\/li>\n<li><a class=\"wp-block-latest-posts__post-title\" href=\"https:\/\/copyassignment.com\/music-recommendation-system-in-machine-learning\/\">Music Recommendation System in Machine Learning<\/a><div class=\"wp-block-latest-posts__post-excerpt\">In this article, we are discussing a music recommendation system using machine learning techniques briefly. Introduction You love listening to music right? Imagine hearing your favorite song on any online music platform let&#8217;s say Spotify. Suppose that the song&#8217;s finished, what now? Yes, the next song gets played automatically. Have you ever imagined, how so?&#8230;<\/div><\/li>\n<li><div class=\"wp-block-latest-posts__featured-image alignleft\"><a href=\"https:\/\/copyassignment.com\/top-15-python-libraries-for-data-science-in-2022\/\" aria-label=\"Top 15 Python Libraries For Data Science in 2022\"><img decoding=\"async\" width=\"150\" height=\"150\" data-src=\"https:\/\/copyassignment.com\/wp-content\/uploads\/2022\/09\/Top-15-Python-Libraries-For-Data-Science-150x150.jpg\" class=\"attachment-thumbnail size-thumbnail wp-post-image lazyload\" alt=\"Top 15 Python Libraries For Data Science\" data-srcset=\"https:\/\/copyassignment.com\/wp-content\/uploads\/2022\/09\/Top-15-Python-Libraries-For-Data-Science-150x150.jpg 150w, https:\/\/copyassignment.com\/wp-content\/uploads\/2022\/09\/Top-15-Python-Libraries-For-Data-Science-600x600.jpg 600w, https:\/\/copyassignment.com\/wp-content\/uploads\/2022\/09\/Top-15-Python-Libraries-For-Data-Science-100x100.jpg 100w\" data-sizes=\"(max-width: 150px) 100vw, 150px\" src=\"data:image\/svg+xml;base64,PHN2ZyB3aWR0aD0iMSIgaGVpZ2h0PSIxIiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciPjwvc3ZnPg==\" style=\"--smush-placeholder-width: 150px; --smush-placeholder-aspect-ratio: 150\/150;\" \/><\/a><\/div><a class=\"wp-block-latest-posts__post-title\" href=\"https:\/\/copyassignment.com\/top-15-python-libraries-for-data-science-in-2022\/\">Top 15 Python Libraries For Data Science in 2022<\/a><div class=\"wp-block-latest-posts__post-excerpt\">Introduction In this informative article, we look at the most important Python Libraries For Data Science and explain how their distinct features may help you develop your data science knowledge. Python has a rich data science library environment. It&#8217;s almost impossible to cover everything in a single article. As a consequence, we&#8217;ve compiled a list&#8230;<\/div><\/li>\n<li><div class=\"wp-block-latest-posts__featured-image alignleft\"><a href=\"https:\/\/copyassignment.com\/top-15-python-libraries-for-machine-learning-in-2022\/\" aria-label=\"Top 15 Python Libraries For Machine Learning\u00a0in 2022\"><img decoding=\"async\" width=\"150\" height=\"150\" data-src=\"https:\/\/copyassignment.com\/wp-content\/uploads\/2022\/09\/Top-15-Python-Libraries-For-Machine-Learning-in-2022-150x150.jpg\" class=\"attachment-thumbnail size-thumbnail wp-post-image lazyload\" alt=\"Top 15 Python Libraries For Machine Learning in 2022\" data-srcset=\"https:\/\/copyassignment.com\/wp-content\/uploads\/2022\/09\/Top-15-Python-Libraries-For-Machine-Learning-in-2022-150x150.jpg 150w, https:\/\/copyassignment.com\/wp-content\/uploads\/2022\/09\/Top-15-Python-Libraries-For-Machine-Learning-in-2022-600x600.jpg 600w, https:\/\/copyassignment.com\/wp-content\/uploads\/2022\/09\/Top-15-Python-Libraries-For-Machine-Learning-in-2022-100x100.jpg 100w\" data-sizes=\"(max-width: 150px) 100vw, 150px\" src=\"data:image\/svg+xml;base64,PHN2ZyB3aWR0aD0iMSIgaGVpZ2h0PSIxIiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciPjwvc3ZnPg==\" style=\"--smush-placeholder-width: 150px; --smush-placeholder-aspect-ratio: 150\/150;\" \/><\/a><\/div><a class=\"wp-block-latest-posts__post-title\" href=\"https:\/\/copyassignment.com\/top-15-python-libraries-for-machine-learning-in-2022\/\">Top 15 Python Libraries For Machine Learning\u00a0in 2022<\/a><div class=\"wp-block-latest-posts__post-excerpt\">Introduction&nbsp; In today&#8217;s digital environment, artificial intelligence (AI) and machine learning (ML) are getting more and more popular. Because of their growing popularity, machine learning technologies and algorithms should be mastered by IT workers. Specifically, Python machine learning libraries are what we are investigating today. We give individuals a head start on the new year&#8230;<\/div><\/li>\n<li><div class=\"wp-block-latest-posts__featured-image alignleft\"><a href=\"https:\/\/copyassignment.com\/machine-learning-in-visual-studio-code\/\" aria-label=\"Setup and Run Machine Learning in Visual Studio Code\"><img decoding=\"async\" width=\"150\" height=\"150\" data-src=\"https:\/\/copyassignment.com\/wp-content\/uploads\/2022\/09\/Setup-and-Run-Machine-Learning-in-Visual-Studio-Code-150x150.jpg\" class=\"attachment-thumbnail size-thumbnail wp-post-image lazyload\" alt=\"Setup and Run Machine Learning in Visual Studio Code\" data-srcset=\"https:\/\/copyassignment.com\/wp-content\/uploads\/2022\/09\/Setup-and-Run-Machine-Learning-in-Visual-Studio-Code-150x150.jpg 150w, https:\/\/copyassignment.com\/wp-content\/uploads\/2022\/09\/Setup-and-Run-Machine-Learning-in-Visual-Studio-Code-600x600.jpg 600w, https:\/\/copyassignment.com\/wp-content\/uploads\/2022\/09\/Setup-and-Run-Machine-Learning-in-Visual-Studio-Code-100x100.jpg 100w\" data-sizes=\"(max-width: 150px) 100vw, 150px\" src=\"data:image\/svg+xml;base64,PHN2ZyB3aWR0aD0iMSIgaGVpZ2h0PSIxIiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciPjwvc3ZnPg==\" style=\"--smush-placeholder-width: 150px; --smush-placeholder-aspect-ratio: 150\/150;\" \/><\/a><\/div><a class=\"wp-block-latest-posts__post-title\" href=\"https:\/\/copyassignment.com\/machine-learning-in-visual-studio-code\/\">Setup and Run Machine Learning in Visual Studio Code<\/a><div class=\"wp-block-latest-posts__post-excerpt\">In this article, we are going to discuss how we can really run our machine learning in Visual Studio Code. Generally, most machine learning projects are developed as &#8216;.ipynb&#8217; in Jupyter notebook or Google Collaboratory. However, Visual Studio Code is powerful among programming code editors, and also possesses the facility to run ML or Data&#8230;<\/div><\/li>\n<li><div class=\"wp-block-latest-posts__featured-image alignleft\"><a href=\"https:\/\/copyassignment.com\/diabetes-prediction-using-machine-learning\/\" aria-label=\"Diabetes prediction using Machine Learning\"><img decoding=\"async\" width=\"150\" height=\"150\" data-src=\"https:\/\/copyassignment.com\/wp-content\/uploads\/2022\/09\/Diabetes-prediction-using-Machine-Learning-150x150.jpg\" class=\"attachment-thumbnail size-thumbnail wp-post-image lazyload\" alt=\"Diabetes prediction using Machine Learning\" data-srcset=\"https:\/\/copyassignment.com\/wp-content\/uploads\/2022\/09\/Diabetes-prediction-using-Machine-Learning-150x150.jpg 150w, https:\/\/copyassignment.com\/wp-content\/uploads\/2022\/09\/Diabetes-prediction-using-Machine-Learning-600x600.jpg 600w, https:\/\/copyassignment.com\/wp-content\/uploads\/2022\/09\/Diabetes-prediction-using-Machine-Learning-100x100.jpg 100w\" data-sizes=\"(max-width: 150px) 100vw, 150px\" src=\"data:image\/svg+xml;base64,PHN2ZyB3aWR0aD0iMSIgaGVpZ2h0PSIxIiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciPjwvc3ZnPg==\" style=\"--smush-placeholder-width: 150px; --smush-placeholder-aspect-ratio: 150\/150;\" \/><\/a><\/div><a class=\"wp-block-latest-posts__post-title\" href=\"https:\/\/copyassignment.com\/diabetes-prediction-using-machine-learning\/\">Diabetes prediction using Machine Learning<\/a><div class=\"wp-block-latest-posts__post-excerpt\">In this article, we are going to build a project on Diabetes Prediction using Machine Learning. Machine Learning is very useful in the medical field to detect many diseases in their early stage. Diabetes prediction is one such Machine Learning model which helps to detect diabetes in humans. Also, we will see how to Deploy&#8230;<\/div><\/li>\n<li><div class=\"wp-block-latest-posts__featured-image alignleft\"><a href=\"https:\/\/copyassignment.com\/15-deep-learning-projects-for-final-year\/\" aria-label=\"15 Deep Learning Projects for Final year\"><img decoding=\"async\" width=\"150\" height=\"150\" data-src=\"https:\/\/copyassignment.com\/wp-content\/uploads\/2022\/08\/15-Deep-Learning-Projects-for-Final-year-150x150.jpg\" class=\"attachment-thumbnail size-thumbnail wp-post-image lazyload\" alt=\"15 Deep Learning Projects for Final year\" data-srcset=\"https:\/\/copyassignment.com\/wp-content\/uploads\/2022\/08\/15-Deep-Learning-Projects-for-Final-year-150x150.jpg 150w, https:\/\/copyassignment.com\/wp-content\/uploads\/2022\/08\/15-Deep-Learning-Projects-for-Final-year-600x600.jpg 600w, https:\/\/copyassignment.com\/wp-content\/uploads\/2022\/08\/15-Deep-Learning-Projects-for-Final-year-100x100.jpg 100w\" data-sizes=\"(max-width: 150px) 100vw, 150px\" src=\"data:image\/svg+xml;base64,PHN2ZyB3aWR0aD0iMSIgaGVpZ2h0PSIxIiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciPjwvc3ZnPg==\" style=\"--smush-placeholder-width: 150px; --smush-placeholder-aspect-ratio: 150\/150;\" \/><\/a><\/div><a class=\"wp-block-latest-posts__post-title\" href=\"https:\/\/copyassignment.com\/15-deep-learning-projects-for-final-year\/\">15 Deep Learning Projects for Final year<\/a><div class=\"wp-block-latest-posts__post-excerpt\">Introduction In this tutorial, we are going to learn about Deep Learning Projects for Final year students. It contains all the beginner, intermediate and advanced level project ideas as well as an understanding of what is deep learning and the applications of deep learning. What is Deep Learning? Deep learning is basically the subset of&#8230;<\/div><\/li>\n<li><a class=\"wp-block-latest-posts__post-title\" href=\"https:\/\/copyassignment.com\/machine-learning-scenario-based-questions\/\">Machine Learning Scenario-Based Questions<\/a><div class=\"wp-block-latest-posts__post-excerpt\">Here, we will be talking about some popular Data Science and Machine Learning Scenario-Based Questions that must be covered while preparing for the interview. We have tried to select the best scenario-based machine learning interview questions which should help our readers in the best ways. Let&#8217;s start, Question 1: Assume that you have to achieve&#8230;<\/div><\/li>\n<li><div class=\"wp-block-latest-posts__featured-image alignleft\"><a href=\"https:\/\/copyassignment.com\/customer-behaviour-analysis-machine-learning-and-python\/\" aria-label=\"Customer Behaviour Analysis &#8211; Machine Learning and Python\"><img decoding=\"async\" width=\"150\" height=\"150\" data-src=\"https:\/\/copyassignment.com\/wp-content\/uploads\/2022\/08\/Customer-Behaviour-Analysis-Machine-Learning-and-Python-150x150.jpg\" class=\"attachment-thumbnail size-thumbnail wp-post-image lazyload\" alt=\"Customer Behaviour Analysis - Machine Learning and Python\" data-srcset=\"https:\/\/copyassignment.com\/wp-content\/uploads\/2022\/08\/Customer-Behaviour-Analysis-Machine-Learning-and-Python-150x150.jpg 150w, https:\/\/copyassignment.com\/wp-content\/uploads\/2022\/08\/Customer-Behaviour-Analysis-Machine-Learning-and-Python-600x600.jpg 600w, https:\/\/copyassignment.com\/wp-content\/uploads\/2022\/08\/Customer-Behaviour-Analysis-Machine-Learning-and-Python-100x100.jpg 100w\" data-sizes=\"(max-width: 150px) 100vw, 150px\" src=\"data:image\/svg+xml;base64,PHN2ZyB3aWR0aD0iMSIgaGVpZ2h0PSIxIiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciPjwvc3ZnPg==\" style=\"--smush-placeholder-width: 150px; --smush-placeholder-aspect-ratio: 150\/150;\" \/><\/a><\/div><a class=\"wp-block-latest-posts__post-title\" href=\"https:\/\/copyassignment.com\/customer-behaviour-analysis-machine-learning-and-python\/\">Customer Behaviour Analysis &#8211; Machine Learning and Python<\/a><div class=\"wp-block-latest-posts__post-excerpt\">Introduction A company runs successfully due to its customers. Understanding the need of customers and fulfilling them through the products is the aim of the company. Most successful businesses achieved the heights by knowing the need of customers and dynamically changing their strategies and development process. Customer Behaviour Analysis is as important as a customer&#8230;<\/div><\/li>\n<li><div class=\"wp-block-latest-posts__featured-image alignleft\"><a href=\"https:\/\/copyassignment.com\/nxnxn-matrix-in-python-3\/\" aria-label=\"NxNxN Matrix in Python 3\"><img decoding=\"async\" width=\"150\" height=\"150\" data-src=\"https:\/\/copyassignment.com\/wp-content\/uploads\/2022\/08\/NxNxN-Matrix-in-Python-3-150x150.jpg\" class=\"attachment-thumbnail size-thumbnail wp-post-image lazyload\" alt=\"NxNxN Matrix in Python 3\" data-srcset=\"https:\/\/copyassignment.com\/wp-content\/uploads\/2022\/08\/NxNxN-Matrix-in-Python-3-150x150.jpg 150w, https:\/\/copyassignment.com\/wp-content\/uploads\/2022\/08\/NxNxN-Matrix-in-Python-3-600x600.jpg 600w, https:\/\/copyassignment.com\/wp-content\/uploads\/2022\/08\/NxNxN-Matrix-in-Python-3-100x100.jpg 100w\" data-sizes=\"(max-width: 150px) 100vw, 150px\" src=\"data:image\/svg+xml;base64,PHN2ZyB3aWR0aD0iMSIgaGVpZ2h0PSIxIiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciPjwvc3ZnPg==\" style=\"--smush-placeholder-width: 150px; --smush-placeholder-aspect-ratio: 150\/150;\" \/><\/a><\/div><a class=\"wp-block-latest-posts__post-title\" href=\"https:\/\/copyassignment.com\/nxnxn-matrix-in-python-3\/\">NxNxN Matrix in Python 3<\/a><div class=\"wp-block-latest-posts__post-excerpt\">A 3d matrix(NxNxN) can be created in Python using lists or NumPy. Numpy provides us with an easier and more efficient way of creating and handling 3d matrices. We will look at the different operations we can provide on a 3d matrix i.e. NxNxN Matrix in Python 3 using NumPy. Create an NxNxN Matrix in&#8230;<\/div><\/li>\n<\/ul>\n\n\n<hr class=\"wp-block-separator has-css-opacity\"\/>\n","protected":false},"excerpt":{"rendered":"<p>In the previous section, we learned about Numpy and how we can use it to load, save, and pre-process data easily by using Numpy Arrays&#8230;.<\/p>\n","protected":false},"author":62,"featured_media":12826,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[22,1137],"tags":[1120,1119,1738,1163],"class_list":["post-5665","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-allcategorites","category-machine-learning","tag-machine-learning","tag-ml","tag-pandas","tag-python-pandas-tutorial-a-complete-introduction-for-beginners","wpcat-22-id","wpcat-1137-id"],"_links":{"self":[{"href":"https:\/\/copyassignment.com\/wp-json\/wp\/v2\/posts\/5665","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/copyassignment.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/copyassignment.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/copyassignment.com\/wp-json\/wp\/v2\/users\/62"}],"replies":[{"embeddable":true,"href":"https:\/\/copyassignment.com\/wp-json\/wp\/v2\/comments?post=5665"}],"version-history":[{"count":0,"href":"https:\/\/copyassignment.com\/wp-json\/wp\/v2\/posts\/5665\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/copyassignment.com\/wp-json\/wp\/v2\/media\/12826"}],"wp:attachment":[{"href":"https:\/\/copyassignment.com\/wp-json\/wp\/v2\/media?parent=5665"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/copyassignment.com\/wp-json\/wp\/v2\/categories?post=5665"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/copyassignment.com\/wp-json\/wp\/v2\/tags?post=5665"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}