Handle the Datetime and coordinates Features

In the real-life dataset, Datetime and coordinates features are often present. To get useful information from Datetime and Coordinates features are also a challenging task. Here, I have explained to extract features from Datetime and Coordinates features with example in Python.

Datetime:

Qbay e-commerce shopping brand want to predict future sales. The Data contain previous 4 years records(2015-2019) of sales on each day. Here, Date is a very important feature and play a significant role to make better predictions. Let’s find some beautiful features from the date feature.

Pandas is a very beautiful python package, which helps to get a month, year, day etc. features from date. 

data['timestemp'] = pd.to_datetime(data['timestemp'], format = '%Y/%m/%d %H:%M:%S')
timestemp_dt= data['timestemp'].dt
data['day'] = timestemp_dt.day
data['day_name'] = timestemp_dt.day_name
data['week'] = timestemp_dt.week # A week ordinal of the year
data['weekOfyear'] = timestemp_dt.weekofyear 
data['dayofweek'] = timestemp_dt.dayofweek
data['dayofyear'] = timestemp_dt.dayofyear
data['quarter'] = timestemp_dt.quarter
data['month'] = timestemp_dt.month
data['month_name'] = timestemp_dt.month_name
data['is_month_start'] = timestemp_dt.is_month_start # Indicates whether the date is the first day of the month.
data['is_month_end'] = timestemp_dt.is_month_end # Indicates whether the date is the last day of the month.
data['is_quarter_start'] = timestemp_dt.is_quarter_start
data['is_quarter_end'] = timestemp_dt.is_quarter_end
data['is_year_start'] = timestemp_dt.is_year_start
data['is_year_end'] = timestemp_dt.is_year_end
data['is_leap_year'] = timestemp_dt.is_leap_year
data['daysinmonth'] = timestemp_dt.daysinmonth # The number of days in the month.
data['timezone'] = timestemp_dt.tz # Return timezone, if any.
data['hour'] = timestemp_dt.hour
data['minute'] = timestemp_dt.minute
data['second'] = timestemp_dt.second

Coordinates:

Coordinates or location features are most often seen in real-life datasets. We can extract helpful information from coordinates and location features like an area are reach or poor, distance to the nearest hospital, school or shopping centre from particular coordinates or locations. We can extract information from existing data and also using additional data from the internet.

 

For Example, A house price prediction data contain feature neighbourhood location of the house. 

Get richest and poorest area
Is_metrocity
Get distance to nearest hospital
Get distance to nearest School
Get distance to nearest Shopping area
Get distance to airport
We can also extract weather information for a particular location
Max/Min temperature in winter
Max/Min temperature in summer
Max/min temperature in monsoon

Leave a Reply

Your email address will not be published. Required fields are marked *

Data Preprocessing Tutorials

Target Encoding for categorical feature

Handle Data Outlier in Machine Learning

Feature Preprocessing for Numerical Features

Different Label Encoding Methods for Categorical Features

Handle Missing Data in Python

What is Data Cleaning?