{"id":4866,"date":"2020-09-16T18:04:34","date_gmt":"2020-09-16T12:34:34","guid":{"rendered":"https:\/\/www.h2kinfosys.com\/blog\/?p=4866"},"modified":"2020-09-16T18:04:36","modified_gmt":"2020-09-16T12:34:36","slug":"data-cleansing-using-pandas","status":"publish","type":"post","link":"https:\/\/www.h2kinfosys.com\/blog\/data-cleansing-using-pandas\/","title":{"rendered":"Data Cleansing Using Pandas"},"content":{"rendered":"\n<p>Data scientists spend a large amount of their time cleaning datasets and getting them down to a form with which they can work. A lot of data scientists argue that the initial steps of obtaining and cleaning data constitute 80% of the job. Therefore, if you are just stepping into this field or planning to step into this field, it is important to be able to deal with messy data, whether that means missing values, inconsistent formatting, malformed records, or nonsensical outliers.<\/p>\n\n\n\n<p>In this article, we will cover a few <a href=\"https:\/\/www.h2kinfosys.com\/blog\/getting-started-with-pandas\/\">pandas libraries<\/a> that are used to clean the data.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>Functions Used for Data Cleaning<\/strong><\/h2>\n\n\n\n<p>After reading the data set into a data frame using .read_csv( ) we will try to clean the Data using different functions<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>Why Should we Rename Columns and Index<\/strong><\/h2>\n\n\n\n<p>If your data was generated by a computer program, it probably has some computer-generated column names, too. Those can be hard to read and understand while working, so if you want to rename a column to something more user-friendly, you can do it using <strong>df.rename()<\/strong><\/p>\n\n\n\n<p>Consider the following DataFrame<\/p>\n\n\n\n<figure class=\"wp-block-table\"><table><tbody><tr><td><strong>&nbsp;&nbsp;&nbsp;<\/strong><\/td><td><strong>A&nbsp;&nbsp;<\/strong><\/td><td><strong>B<\/strong><\/td><\/tr><tr><td><strong>0<\/strong><\/td><td>1<\/td><td>4<\/td><\/tr><tr><td><strong>1<\/strong><\/td><td>2<\/td><td>5<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<p><code>df.rename(columns={\"A\": \"a\", \"B\": \"b\"})<\/code><\/p>\n\n\n\n<p><strong>Output:<\/strong><\/p>\n\n\n\n<figure class=\"wp-block-table\"><table><tbody><tr><td><strong>&nbsp;&nbsp;&nbsp;<\/strong><\/td><td><strong>a&nbsp;&nbsp;<\/strong><\/td><td><strong>b<\/strong><\/td><\/tr><tr><td><strong>0<\/strong><\/td><td>1<\/td><td>4<\/td><\/tr><tr><td><strong>1<\/strong><\/td><td>2<\/td><td>5<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<p>We can also rename the index using .rename()<\/p>\n\n\n\n<p><code>df.rename(index={0: \"x\", 1: \"y\"})<\/code><\/p>\n\n\n\n<figure class=\"wp-block-table\"><table><tbody><tr><td><strong>&nbsp;&nbsp;&nbsp;<\/strong><\/td><td><strong>a&nbsp;&nbsp;<\/strong><\/td><td><strong>b<\/strong><\/td><\/tr><tr><td><strong>x&nbsp;&nbsp;<\/strong><\/td><td>1<\/td><td>4<\/td><\/tr><tr><td><strong>y&nbsp;&nbsp;<\/strong><\/td><td>2<\/td><td>5<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<p>Missing data is always a problem in real-life scenarios. Areas like machine learning and <a href=\"https:\/\/en.wikipedia.org\/wiki\/Data_mining\" rel=\"nofollow noopener\" target=\"_blank\">data mining<\/a> face severe issues in the accuracy of their model predictions because of the poor quality of data caused by missing values. In these areas, missing value treatment is a major point of focus to make their models more accurate and valid.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>When and Why Is Data Missed?<\/strong><\/h2>\n\n\n\n<p>Let us consider an online survey for a product. Many times, people do not share all the information related to them. Few people share their experience, but not how long they are using the product; few people share how long they are using the product, their experience but not their contact information. Thus, in some or the other way, a part of data is always missing, and this is very common in real-time.<\/p>\n\n\n\n<p>In Pandas missing data is represented by two value:&nbsp;<\/p>\n\n\n\n<p><strong>None<\/strong>: None is a Python singleton object that is often used for missing<strong> <\/strong>data in Python code.&nbsp;<\/p>\n\n\n\n<p><strong>NaN<\/strong>: NaN (an acronym for Not a Number), is a special floating point value recognized by all systems that use the standard IEEE floating-point representation.<\/p>\n\n\n\n<p>Let us now see how to identify missing values in our Data Set<\/p>\n\n\n\n<p>Consider the following Data Set<\/p>\n\n\n\n<figure class=\"wp-block-table\"><table><tbody><tr><td><strong>&nbsp;&nbsp;&nbsp;&nbsp;<\/strong><\/td><td><strong>one&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<\/strong><\/td><td><strong>two&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<\/strong><\/td><td><strong>three&nbsp;&nbsp;&nbsp;&nbsp;<\/strong><\/td><\/tr><tr><td><strong>a&nbsp;&nbsp;&nbsp;<\/strong><\/td><td>-1.359063<\/td><td>1.613255<\/td><td>-0.669396<\/td><\/tr><tr><td><strong>b&nbsp;&nbsp;&nbsp;<\/strong><\/td><td>&nbsp; &nbsp; &nbsp; NaN&nbsp;&nbsp;<\/td><td>&nbsp; &nbsp; NaN&nbsp;&nbsp;<\/td><td>&nbsp; &nbsp; &nbsp; NaN<\/td><\/tr><tr><td><strong>c&nbsp;&nbsp;&nbsp;<\/strong><\/td><td>0.885117<\/td><td>0.609271<\/td><td>0.330818<\/td><\/tr><tr><td><strong>d&nbsp;&nbsp;&nbsp;<\/strong><\/td><td>&nbsp; &nbsp; &nbsp; NaN&nbsp;&nbsp;<\/td><td>&nbsp; &nbsp; NaN&nbsp;&nbsp;<\/td><td>&nbsp; &nbsp; &nbsp; NaN<\/td><\/tr><tr><td><strong>e&nbsp;&nbsp;&nbsp;<\/strong><\/td><td>-0.136086<\/td><td>1.132808<\/td><td>0.496091<\/td><\/tr><tr><td><strong>f&nbsp;&nbsp;&nbsp;<\/strong><\/td><td>0.210065<\/td><td>0.533174<\/td><td>0.111560<\/td><\/tr><tr><td><strong>g&nbsp;&nbsp;&nbsp;<\/strong><\/td><td>&nbsp; &nbsp; &nbsp; NaN&nbsp;&nbsp;<\/td><td>&nbsp; &nbsp; NaN&nbsp;&nbsp;<\/td><td>&nbsp; &nbsp; &nbsp; NaN<\/td><\/tr><tr><td><strong>h&nbsp;&nbsp;&nbsp;<\/strong><\/td><td>1.027689<\/td><td>0.630037<\/td><td>0.727022<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<p>Now we will find the missing values in the data set using the function&nbsp; &nbsp; .isnull( )<\/p>\n\n\n\n<p><code>df.isnull()<\/code><\/p>\n\n\n\n<p><strong>Output:<\/strong><\/p>\n\n\n\n<figure class=\"wp-block-table\"><table><tbody><tr><td><strong>&nbsp;&nbsp;&nbsp;<\/strong><\/td><td><strong>&nbsp; one&nbsp;&nbsp;<\/strong><\/td><td><strong>&nbsp; two&nbsp;&nbsp;<\/strong><\/td><td><strong>three<\/strong><\/td><\/tr><tr><td><strong>a&nbsp;&nbsp;<\/strong><\/td><td>False&nbsp;&nbsp;<\/td><td>False&nbsp;&nbsp;<\/td><td>FALSE<\/td><\/tr><tr><td><strong>b&nbsp;&nbsp;<\/strong><\/td><td>True&nbsp;&nbsp;<\/td><td>True&nbsp;&nbsp;<\/td><td>True<\/td><\/tr><tr><td><strong>c&nbsp;&nbsp;<\/strong><\/td><td>False&nbsp;&nbsp;<\/td><td>False&nbsp;&nbsp;<\/td><td>FALSE<\/td><\/tr><tr><td><strong>d&nbsp;&nbsp;<\/strong><\/td><td>True&nbsp;&nbsp;<\/td><td>True&nbsp;&nbsp;<\/td><td>True<\/td><\/tr><tr><td><strong>e&nbsp;&nbsp;<\/strong><\/td><td>False&nbsp;&nbsp;<\/td><td>False&nbsp;&nbsp;<\/td><td>FALSE<\/td><\/tr><tr><td><strong>f&nbsp;&nbsp;<\/strong><\/td><td>False&nbsp;&nbsp;<\/td><td>False&nbsp;&nbsp;<\/td><td>FALSE<\/td><\/tr><tr><td><strong>g&nbsp;&nbsp;<\/strong><\/td><td>True&nbsp;&nbsp;<\/td><td>True&nbsp;&nbsp;<\/td><td>True<\/td><\/tr><tr><td><strong>h&nbsp;&nbsp;<\/strong><\/td><td>False&nbsp;&nbsp;<\/td><td>False&nbsp;&nbsp;<\/td><td>FALSE<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<p>.isnull() checks every column for NULL values and a boolean series is returned by the isnull() method which stores True for NaN value and False for a Not null value.<\/p>\n\n\n\n<p>We can also use .notnull() function to find the null values. It is opposite of .isnull()<\/p>\n\n\n\n<p><code>df.notnull()<\/code><\/p>\n\n\n\n<p><strong>Output:<\/strong><\/p>\n\n\n\n<figure class=\"wp-block-table\"><table><tbody><tr><td><strong>&nbsp;&nbsp;&nbsp;<\/strong><\/td><td><strong>&nbsp; one&nbsp;&nbsp;<\/strong><\/td><td><strong>&nbsp; two&nbsp;&nbsp;<\/strong><\/td><td><strong>three<\/strong><\/td><\/tr><tr><td><strong>a&nbsp;&nbsp;<\/strong><\/td><td>True&nbsp;&nbsp;<\/td><td>True&nbsp;&nbsp;<\/td><td>True<\/td><\/tr><tr><td><strong>b&nbsp;&nbsp;<\/strong><\/td><td>False&nbsp;&nbsp;<\/td><td>False&nbsp;&nbsp;<\/td><td>FALSE<\/td><\/tr><tr><td><strong>c&nbsp;&nbsp;<\/strong><\/td><td>True&nbsp;&nbsp;<\/td><td>True&nbsp;&nbsp;<\/td><td>True<\/td><\/tr><tr><td><strong>d&nbsp;&nbsp;<\/strong><\/td><td>False&nbsp;&nbsp;<\/td><td>False&nbsp;&nbsp;<\/td><td>FALSE<\/td><\/tr><tr><td><strong>e&nbsp;&nbsp;<\/strong><\/td><td>True&nbsp;&nbsp;<\/td><td>True&nbsp;&nbsp;<\/td><td>True<\/td><\/tr><tr><td><strong>f&nbsp;&nbsp;<\/strong><\/td><td>True&nbsp;&nbsp;<\/td><td>True&nbsp;&nbsp;<\/td><td>True<\/td><\/tr><tr><td><strong>g&nbsp;&nbsp;<\/strong><\/td><td>False&nbsp;&nbsp;<\/td><td>False&nbsp;&nbsp;<\/td><td>FALSE<\/td><\/tr><tr><td><strong>h&nbsp;&nbsp;<\/strong><\/td><td>True&nbsp;&nbsp;<\/td><td>True&nbsp;&nbsp;<\/td><td>True<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<p>.notnull() checks every column is checked for NULL values and a boolean series is returned by the notnull() method which stores True for every NON-NULL value and False for a null value.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>How to Drop rows with Nan values<\/strong><\/h2>\n\n\n\n<p>There are several options for handling missing values each with its PROS and CONS. However, the choice of what should be done is largely dependent on the nature of our data and the missing values. Below is a summary highlight of several options we have for handling missing values.<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li>Drop the missing values<\/li><\/ul>\n\n\n\n<ul class=\"wp-block-list\"><li>Fill the missing values<\/li><\/ul>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>Drop the missing values<\/strong><\/h2>\n\n\n\n<p>.dropna() function this function drop Rows Columns off datasets with Null values<\/p>\n\n\n\n<p>Consider the following Data Set<\/p>\n\n\n\n<figure class=\"wp-block-table\"><table><tbody><tr><td><strong>&nbsp;&nbsp;&nbsp;&nbsp;<\/strong><\/td><td><strong>one&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<\/strong><\/td><td><strong>two&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<\/strong><\/td><td><strong>three&nbsp;&nbsp;&nbsp;&nbsp;<\/strong><\/td><\/tr><tr><td><strong>a&nbsp;&nbsp;&nbsp;<\/strong><\/td><td>-1.359063<\/td><td>1.613255<\/td><td>-0.669396<\/td><\/tr><tr><td><strong>b&nbsp;&nbsp;&nbsp;<\/strong><\/td><td>&nbsp; &nbsp; &nbsp; NaN&nbsp;&nbsp;<\/td><td>&nbsp; &nbsp; NaN&nbsp;&nbsp;<\/td><td>&nbsp; &nbsp; &nbsp; NaN<\/td><\/tr><tr><td><strong>c&nbsp;&nbsp;&nbsp;<\/strong><\/td><td>0.885117<\/td><td>0.609271<\/td><td>0.330818<\/td><\/tr><tr><td><strong>d&nbsp;&nbsp;&nbsp;<\/strong><\/td><td>&nbsp; &nbsp; &nbsp; NaN&nbsp;&nbsp;<\/td><td>&nbsp; &nbsp; NaN&nbsp;&nbsp;<\/td><td>&nbsp; &nbsp; &nbsp; NaN<\/td><\/tr><tr><td><strong>e&nbsp;&nbsp;&nbsp;<\/strong><\/td><td>-0.136086<\/td><td>1.132808<\/td><td>0.496091<\/td><\/tr><tr><td><strong>f&nbsp;&nbsp;&nbsp;<\/strong><\/td><td>0.210065<\/td><td>0.533174<\/td><td>0.111560<\/td><\/tr><tr><td><strong>g&nbsp;&nbsp;&nbsp;<\/strong><\/td><td>&nbsp; &nbsp; &nbsp; NaN&nbsp;&nbsp;<\/td><td>&nbsp; &nbsp; NaN&nbsp;&nbsp;<\/td><td>&nbsp; &nbsp; &nbsp; NaN<\/td><\/tr><tr><td><strong>h&nbsp;&nbsp;&nbsp;<\/strong><\/td><td>1.027689<\/td><td>0.630037<\/td><td>0.727022<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<p><code>df.dropna()<\/code><\/p>\n\n\n\n<p><strong>Output:<\/strong><\/p>\n\n\n\n<figure class=\"wp-block-table\"><table><tbody><tr><td><\/td><td><\/td><td><\/td><td><\/td><\/tr><tr><td><strong>&nbsp;&nbsp;&nbsp;&nbsp;<\/strong><\/td><td>one&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<\/td><td>two&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<\/td><td>three&nbsp;&nbsp;&nbsp;&nbsp;<\/td><\/tr><tr><td><strong>a&nbsp;&nbsp;&nbsp;<\/strong><\/td><td>-1.359063<\/td><td>1.613255<\/td><td>-0.669396<\/td><\/tr><tr><td><strong>c&nbsp;&nbsp;&nbsp;<\/strong><\/td><td>0.885117<\/td><td>0.609271<\/td><td>0.330818<\/td><\/tr><tr><td><strong>e&nbsp;&nbsp;&nbsp;<\/strong><\/td><td>-0.136086<\/td><td>1.132808<\/td><td>0.496091<\/td><\/tr><tr><td><strong>f&nbsp;&nbsp;&nbsp;<\/strong><\/td><td>0.210065<\/td><td>0.533174<\/td><td>0.111560<\/td><\/tr><tr><td><strong>h&nbsp;&nbsp;&nbsp;<\/strong><\/td><td>1.027689<\/td><td>0.630037<\/td><td>0.727022<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>Fill the missing values<\/strong><\/h2>\n\n\n\n<p>Pandas df.replace() function is used to replace a string, regex, list, dictionary, series, number etc. from a dataframe. This is a very rich function as it has many variations.<\/p>\n\n\n\n<p>Using this .replace() function we can replace we replace all the NaN with whatever value\u2019s we like<\/p>\n\n\n\n<p>Now we will replace all the <strong>NaN<\/strong> with <strong>\u20180\u2019<\/strong><\/p>\n\n\n\n<p>df.replace(np.nan,0) \/\/(orginal value,replaced value)<\/p>\n\n\n\n<p><strong>Output:<\/strong><\/p>\n\n\n\n<figure class=\"wp-block-table\"><table><tbody><tr><td><strong>&nbsp;&nbsp;&nbsp;&nbsp;<\/strong><\/td><td><strong>one&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<\/strong><\/td><td><strong>two&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<\/strong><\/td><td><strong>three&nbsp;&nbsp;&nbsp;&nbsp;<\/strong><\/td><\/tr><tr><td><strong>a&nbsp;&nbsp;&nbsp;<\/strong><\/td><td>-1.359063<\/td><td>1.613255<\/td><td>-0.669396<\/td><\/tr><tr><td><strong>b&nbsp;&nbsp;&nbsp;<\/strong><\/td><td>0<\/td><td>0<\/td><td>0<\/td><\/tr><tr><td><strong>c&nbsp;&nbsp;&nbsp;<\/strong><\/td><td>0.885117<\/td><td>0.609271<\/td><td>0.330818<\/td><\/tr><tr><td><strong>d&nbsp;&nbsp;&nbsp;<\/strong><\/td><td>0<\/td><td>0<\/td><td>0<\/td><\/tr><tr><td><strong>e&nbsp;&nbsp;&nbsp;<\/strong><\/td><td>-0.136086<\/td><td>1.132808<\/td><td>0.496091<\/td><\/tr><tr><td><strong>f&nbsp;&nbsp;&nbsp;<\/strong><\/td><td>0.210065<\/td><td>0.533174<\/td><td>0.111560<\/td><\/tr><tr><td><strong>g&nbsp;&nbsp;&nbsp;<\/strong><\/td><td>0<\/td><td>0<\/td><td>0<\/td><\/tr><tr><td><strong>h&nbsp;&nbsp;&nbsp;<\/strong><\/td><td>1.027689<\/td><td>0.630037<\/td><td>0.727022<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<p>You can also replace the NaN with mean, median, mode and we can also impute values using machine learning models .<\/p>\n\n\n\n<p>We will learn about statistical summary calculations in next article\u2019s<\/p>\n\n\n\n<p>Now we will learn how to convert the datatypes of the variables&nbsp;<\/p>\n\n\n\n<p>When doing data analysis, it is important to make sure you are using the correct data types; otherwise, you may get unexpected results or errors. In the case of pandas, it will correctly infer data types in many cases and you can move on with your analysis without any further thought on the topic.<\/p>\n\n\n\n<p>Despite how well pandas works, at some point in your data analysis processes, you will likely need to explicitly convert data from one type to another.&nbsp;<\/p>\n\n\n\n<p>Now we will discuss the basic pandas data types, how they map to python and numpy data types, and the options for converting from one pandas type to another.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>Pandas Data&nbsp;Types<\/strong><\/h2>\n\n\n\n<p>A data type is essentially an internal construct that a programming language uses to understand how to store and manipulate data. For instance, a program needs to understand that you can add two numbers together like 5 + 10 to get 15. Or, if you have two strings such as \u201ccat\u201d and \u201cdog\u201d you could concatenate (add) them together to get&nbsp;\u201ccatdog.\u201d<\/p>\n\n\n\n<p>A possible confusing point about pandas data types is that there is some overlap between pandas, and numpy. This table summarizes the key&nbsp;points:<\/p>\n\n\n\n<figure class=\"wp-block-table\"><table><tbody><tr><td>Pandas dtype<\/td><td>NumPy type<\/td><td>Usage<\/td><\/tr><tr><td>object<\/td><td>string_, unicode_, mixed types<\/td><td>Text or mixed numeric<\/td><\/tr><tr><td>int64<\/td><td>int_, int8, int16, int32, int64, uint8, uint16, uint32, uint64<\/td><td>Integer numbers<\/td><\/tr><tr><td>float64<\/td><td>float_, float16, float32, float64<\/td><td>Floating point numbers<\/td><\/tr><tr><td>bool<\/td><td>bool_<\/td><td>True\/False values<\/td><\/tr><tr><td>datetime64<\/td><td>datetime64[ns]<\/td><td>Date and time values<\/td><\/tr><tr><td>category<\/td><td>NA<\/td><td>Finite list of text values<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<p>Now we will focus on the following pandas data types and learn how to convert them from one form to another form&nbsp;<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li>object<\/li><\/ul>\n\n\n\n<ul class=\"wp-block-list\"><li>int64<\/li><\/ul>\n\n\n\n<ul class=\"wp-block-list\"><li>float64<\/li><\/ul>\n\n\n\n<p>Consider a DataFrame<\/p>\n\n\n\n<figure class=\"wp-block-table\"><table><tbody><tr><td><strong>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<\/strong><\/td><td><strong>Age&nbsp;&nbsp;<\/strong><\/td><td><strong>Height&nbsp;&nbsp;<\/strong><\/td><td><strong>Weight<\/strong><\/td><\/tr><tr><td><strong>Krishna&nbsp;&nbsp;<\/strong><\/td><td>25.5<\/td><td>5.40<\/td><td>45.5<\/td><\/tr><tr><td><strong>Ram&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<\/strong><\/td><td>45.0<\/td><td>5.11<\/td><td>50.0<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<p>As we all know that age is an integer value but if we closely observe the data frame age values is in float form<\/p>\n\n\n\n<p>We can check the datatypes of every column by using .dtypes<\/p>\n\n\n\n<p><code>df.dtypes<\/code><\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">Age &nbsp; &nbsp; &nbsp; float64\nHeight&nbsp; &nbsp; float64\nWeight&nbsp; &nbsp; float64\ndtype: object<\/pre>\n\n\n\n<p>It is showing that Age is a float in-order to convert it into int we will use .astype()<\/p>\n\n\n\n<p><code>df[\u2018Age\u2019].astype(\u2018int32\u2019)<\/code><\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">Ram&nbsp; &nbsp; &nbsp; &nbsp; 25\nKrishna&nbsp; &nbsp; 45\nName: Age, dtype: int32<\/pre>\n\n\n\n<p>Now we can see that Age column is now converted into int datatype<\/p>\n\n\n\n<p>We will see the rest of the pandas applications in the next article\u2026\u2026<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Data scientists spend a large amount of their time cleaning datasets and getting them down to a form with which they can work. A lot of data scientists argue that the initial steps of obtaining and cleaning data constitute 80% of the job. Therefore, if you are just stepping into this field or planning to [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":4892,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[500],"tags":[1369,1367,1368],"class_list":["post-4866","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-data-science-using-python-tutorials","tag-data-cleaning-functions","tag-data-cleansing-using-pandas","tag-pandas-data-types"],"_links":{"self":[{"href":"https:\/\/www.h2kinfosys.com\/blog\/wp-json\/wp\/v2\/posts\/4866","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.h2kinfosys.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.h2kinfosys.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.h2kinfosys.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.h2kinfosys.com\/blog\/wp-json\/wp\/v2\/comments?post=4866"}],"version-history":[{"count":0,"href":"https:\/\/www.h2kinfosys.com\/blog\/wp-json\/wp\/v2\/posts\/4866\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.h2kinfosys.com\/blog\/wp-json\/wp\/v2\/media\/4892"}],"wp:attachment":[{"href":"https:\/\/www.h2kinfosys.com\/blog\/wp-json\/wp\/v2\/media?parent=4866"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.h2kinfosys.com\/blog\/wp-json\/wp\/v2\/categories?post=4866"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.h2kinfosys.com\/blog\/wp-json\/wp\/v2\/tags?post=4866"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}