5

Data Wrangling Solutions — Convert Continuous Variables Into Categorical

 9 months ago
source link: https://ujjwal-dalmia.medium.com/data-wrangling-solutions-convert-continuous-variables-into-categorical-3d0fee1d8b53
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client

Data Wrangling Solutions — Convert Continuous Variables Into Categorical

A one-step solution to bin the numerical variables.

0*Ku9CdJXBVxipRtvK

Photo by Paweł Czerwiński on Unsplash

During the data preprocessing stage, we often end up binning continuous variables into logical groups. When I started with my data science journey, I did it by writing custom If-Else conditions. Binning variables through this approach is time-consuming and remains very custom for one variable (can’t be replicated). If the challenge mentioned here sounds familiar, then this tutorial is for you. The image below will give a visual detail on the challenge we are trying to solve.

1*-nbdkoFt6r0mB0_3tqiTcw.png

Binning Numerical Variables (Image by Author)

Assumption and Recommendation

Being hands-on is the key to master programming. We recommend that you continue to implement the codes as you follow through with the tutorial. The sample data and the associated Jupiter notebook is available in the Scenario_10 folder of this GitHub link.

If you are new to GitHub and want to learn it, please go through this tutorial. To set up a new Python environment on your system, please go through this tutorial.

Following is the list of Python concepts and pandas functions/ methods used in the tutorial:

Pandas functions

  • read_csv

Solution

Step 1 — Keeping the data ready

For this tutorial, we are using the famous cars dataset. The dictionary for this data set and the sample data snapshot is as follows:

  • Model — Name of car model
  • Actual MPG — Mileage of the car model
  • Cylinders — # of cylinders in the car model
  • Horsepower — Power of the car model
  • Weight — Weight of the car model
  • Year — Year of manufacturing
  • Origin — Country of manufacturing

About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK