top of page
Search

# Data Science Assignment Help | What is Data Wrangling? - Codersarts

## What is data Wrangling?

Data Wrangling is the process of converting data from the initial format to a format that may be readable and better for analysis.

Here we use the below data set :

## Import pandas

Open Jupyter notebook or any online jupyter notebook editor and import pandas-

import pandas as pd

import matplotlib.pylab as plt

"length","width","height","curb-weight","engine-type", "num-of-cylinders", "engine-size","fuel

-system","bore","stroke","compression-ratio","horsepower", "peak-rpm","city-mpg","highway-mpg","price"]

Show data in tabular form

Data display in tabular form and you will face some challenges like this-

• identify missing data

• deal with missing data

• correct data format

### Identify and handle missing values

Identify missing values

#### df.replace("?", np.nan, inplace = True)

It set NaN at first five index row where "?" is presented.

### How to detect missing data:

There are two method used to detect missing data.

• .isnull() - Return true at the place of missing data and other place return false.

• .notnull() - Return true at the placed data and false at missing data place.

Example:

mis_value = df.isnull()

### Using for loop:

Example:

Write this for loop and find result

for column in mis_value .columns.values.tolist():

print(column)

print (mis_value [column].value_counts())

print("")

### How we will work with missing data

Drop data

• drop the whole row- Let suppose any value is necessary like price but it is missing at any row then we remove whole row.

• drop the whole column - let we suppose if price is missing at any column then it reason of delete whole column because price is necessary for data science to calculate price.

Replace data

• replace it by mean

• replace it by frequency - replace as per frequency for example- 84 % is good, and 16% bad, then 16% remove by good.

• replace it based on other functions

### Calculate the average of any column

Example

avg= df["column name"].astype("float").mean(axis=0)

print("Average of column name:", avg)

### Replace "NaN" by mean value - of any column

Example

df["column_name"].replace(np.nan, avg, inplace=True)

### Calculate the mean value - of any column

Example

avg=df['column_name'].astype('float').mean(axis=0)

print("Average of column_name:", avg)

### Replace NaN by mean value

Example

df["column_name"].replace(np.nan, avg, inplace=True)

### How count each column data separately

Use value_counts() function

Example:

df['column_name'].value_counts()

Output like this: let suppose column_name is qualification then count each qualification with name.

mca 78

bca 45

Calculate for us the most common (max) automatically

df['column_name'].value_counts().idxmax()

Output:

mca 78

### Replace NaN by most frequent

Example

df["column_name"].replace(np.nan, "four", inplace=True)

All NaN replace by most frequent- by "four"

### Drop whole row with NaN in "Column_name" column

Let suppose column_name is "price"

df.dropna(subset=["price"], axis=0, inplace=True)

# reset index, because we dropped two rows

df.reset_index(drop=True, inplace=True)

### Correct data format

In Pandas, we use

• .dtype() to check the data type

• .astype() to change the data type

### Show list of data type:

Use this syntax to list data type -

syntax:

df.dtypes

### How to convert data type in proper format

There are different type of data format used -

Syntax:

df[["column1", "column2"]] = df[["column1", "column2"]].astype("float")

df[["column3"]] = df[["column3"]].astype("int")

df[["column4"]] = df[["column4"]].astype("float")

df[["column5"]] = df[["column5"]].astype("float")

Again check it by using following -

It show list so that you can verify that data type is change or not

Syntax:

df.dtypes

## Data Standardization

What is Standardization?

Standardization is the process of transforming data into a common format which allows the researcher to make the meaningful comparison.

Example

Transform mpg to L/100km

The formula for unit conversion is

L/100km = 235 / mpg

First go through the data to verify it by using this syntax-

Syntax:

Example:

Convert mpg to L/100km by mathematical operation

df['city-L/100km'] = 235/df["city-mpg"]

It add new column city-L/100km after change the value of column city-mpg

## Data Normalization

Why normalization?

Normalization is the process of transforming values of several variables into a similar range.

Example:

# replace (original value) by (original value)/(maximum value)

df['length'] = df['length']/df['length'].max()

df['width'] = df['width']/df['width'].max()

## Binning

Why binning?

Binning is a process of transforming continuous numerical variables into discrete categorical 'bins', for grouped analysis.

## Indicator variable (or dummy variable)

What is an indicator variable?

An indicator variable (or dummy variable) is a numerical variable used to label categories. They are called 'dummies' because the numbers themselves don't have inherent meaning.

Why we use indicator variables?

So we can use categorical variables for regression analysis in the later modules.

## List of Other Codersarts Assignment Help Expert Services

If you like Codersarts blog and looking for Programming Assignment Help Service,Database Development Service,Web development service,Mobile App Development, Project help, Hire Software Developer,Programming tutors help and suggestion Â you can send mail atÂ contact@codersarts.com.

Please write your suggestion in comment section below if you find anything incorrect in this blog post