Created
March 7, 2020 20:20
-
-
Save Paulooh007/756d89416891c84338192354a6eae37f to your computer and use it in GitHub Desktop.
feat_eng
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# The first step is to convert the data type of the column (TRANSACTION TIME) to DateTime. | |
# That can be done using .to_datetime() method in Pandas. | |
train['transaction time']= pd.to_datetime(train['transaction time']) | |
train['hour'] = train['transaction time'].dt.hour #returns the hour of the datetime(range 1 - 24) | |
train['dayofweek_name'] = train['transaction time'].dt.weekday_name #day of week of transaction | |
train['is_weekend'] = np.where(train['dayofweek_name'].isin(['Sunday','Saturday']),1,0) #weekend or not | |
#Getting the period of the day from the hour feature | |
bins = [0,4,8,12,16,20,24] | |
period = ['Late Night', 'Early Morning','Morning','Noon','Eve','Night'] | |
train['period_of_day'] = pd.cut(train['hour'], bins=bins, labels=period) | |
#Getting the recent amount withdrawn or deposited | |
train['prev_tran'] = train['current bank amount'] - train['last bank amount'] | |
#credit if the value is positive or debit if otherwise | |
train['credit_or_debit'] = ['credit' if x > 0 else 'debit' for x in train['prev_tran'] ] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment