<jupyter_start><jupyter_text>Objective:- Understand when and why employees are most likely to leave (people analytics)- Build a model to predict employee retention- Create a table with date, employee_headcount ( employed on that specific day), company_id- Derive main driving factors for employee churn- Consider potential additional variables that can aid in predicting employee retention<jupyter_code>import  warnings
warnings.simplefilter('ignore')
import datetime
import numpy as np
import pandas as pd
import seaborn as sns
import matplotlib.pyplot as plt
import graphviz
from sklearn import tree
from sklearn.tree import DecisionTreeClassifier
from sklearn.preprocessing import LabelEncoder

%matplotlib inline

data = pd.read_csv('data/employee_retention_data.csv', parse_dates=['join_date', 'quit_date'])
data.head()
data.info()
data.describe(include = 'all')
# Make sure employee ids are unique
assert data['employee_id'].nunique() == len(data)

# Null information
data.isnull().sum()<jupyter_output><empty_output><jupyter_text>Create Table for day, employee_headcount, and company_id<jupyter_code>#check seniority outlier
data.sort_values('seniority', ascending=False).head()<jupyter_output><empty_output><jupyter_text>The top two items are the outliners<jupyter_code>data.sort_values('salary', ascending=False).head(10)
#covert type to int
data = data.astype({'employee_id':'int64'})
data.set_index('employee_id', inplace=True)
data.head()
# Create an intermediate table with the extreme seniority values removed
data = data.drop([604052, 97289])
# Define the start date and end dates
start_date = datetime.datetime.strptime('2011-01-24', '%Y-%m-%d')
end_date = datetime.datetime.strptime('2015-12-13', '%Y-%m-%d')
assert data['join_date'].max()<=end_date
assert data['join_date'].min()>=start_date
assert data['quit_date'].max()<=end_date
assert data['quit_date'].min()>start_date
1+1
unique_date = pd.date_range(start=start_date, end = end_date)
unique_columns = sorted(data['company_id'].unique(0))

day = []
company = []
headcount = []

#loop through date and company id

for one_day in unique_date:
    for one_cp in unique_company:
         
data[['company_id','dept']]<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.11597472924187725, 'fraction_numerical': 0.015342960288808664, 'mean_word_length': 7.003610108303249, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 15, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '3', 'dir': 'jupyter-structured-clean-dedup', 'id': '636464', 'license': 'Apache-2.0', 'n_tokens_mistral': 722, 'n_tokens_neox': 686, 'n_words': 191, 'path': 'EmployeeRetention/EmployeeRetention.ipynb', 'repo_name': 'JingyuZHANG/DataScience_Python', 'size': '2216'}