This file contains hidden or 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
| # Replace null values with string "no" (i.e., meaning that employee has not left the company) | |
| df['Departure Date'] = df['Departure Date'].fillna("no") | |
| # Get a list of all months from the hiring date of the first employee until current month | |
| all_months = pd.date_range(df["Hiring Date"].unique()[0], datetime.datetime.today().strftime('%m/%d/%Y'), freq='MS').strftime("%Y-%b").tolist() | |
| # Initialize list for cummulative employees | |
| cummulative_employees = [] | |
| # Loop through all the months in list |
This file contains hidden or 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
| # Import libraries and dependencies | |
| import pandas as pd | |
| import datetime | |
| import matplotlib.pyplot as plt | |
| %matplotlib inline | |
| # Read employees csv file | |
| df = pd.read_csv("employees.csv") | |
| # Display top rows |
This file contains hidden or 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
| def max_repeated_character(word): | |
| # Validate that provided word is not an empty string | |
| if word != "": | |
| # Initialize variables | |
| repeated_character = word[0] | |
| character_repeated_times = 1 | |
| max_repeated_times = 1 |
This file contains hidden or 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
| # Rule 3 - Lower | |
| for i in range(5, len(df_grouped['x_bar'])+1): | |
| if((df_grouped['x_bar'][i-4] < df_grouped['-1s'][i-4] and df_grouped['x_bar'][i-3] < df_grouped['-1s'][i-3] and df_grouped['x_bar'][i-2] < df_grouped['-1s'][i-2] and df_grouped['x_bar'][i-1] < df_grouped['-1s'][i-1]) or | |
| (df_grouped['x_bar'][i-4] < df_grouped['-1s'][i-4] and df_grouped['x_bar'][i-3] < df_grouped['-1s'][i-3] and df_grouped['x_bar'][i-2] < df_grouped['-1s'][i-2] and df_grouped['x_bar'][i] < df_grouped['-1s'][i]) or | |
| (df_grouped['x_bar'][i-4] < df_grouped['-1s'][i-4] and df_grouped['x_bar'][i-2] < df_grouped['-1s'][i-2] and df_grouped['x_bar'][i-1] < df_grouped['-1s'][i-1] and df_grouped['x_bar'][i] < df_grouped['-1s'][i]) or | |
| (df_grouped['x_bar'][i-4] < df_grouped['-1s'][i-4] and df_grouped['x_bar'][i-3] < df_grouped['-1s'][i-3] and df_grouped['x_bar'][i-1] < df_grouped['-1s'][i-1] and df_grouped['x_bar'][i] < df_grouped['-1s'][i]) or | |
| (df_grouped['x_bar'][i-3] < df_grouped['-1s'][i-3] and df_grouped['x |
This file contains hidden or 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
| # Look for at least one False value in each of the control chart rules | |
| analysis.all() |
This file contains hidden or 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
| # Define outcomes data frame | |
| analysis = pd.DataFrame({'R1_lower':R1_lower, | |
| 'R1_upper':R1_upper, | |
| 'R2_lower':R2_lower, | |
| 'R2_upper':R2_upper, | |
| 'R3_lower':R3_lower, | |
| 'R3_upper':R3_upper, | |
| 'R4_lower':R4_lower, | |
| 'R4_upper':R4_upper}) |
This file contains hidden or 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
| # Rule 4 - Lower | |
| for i in range(8,len(df_grouped)+1): | |
| if (df_grouped["x_bar"][i-8:i] < df_grouped["x_bar_bar"][1]).all(): | |
| R4_lower.append(False) | |
| else: | |
| R4_lower.append(True) | |
| # Rule 4 - Upper | |
| for i in range(8,len(df_grouped)+1): | |
| if (df_grouped["x_bar"][i-8:i] > df_grouped["x_bar_bar"][1]).all(): |
This file contains hidden or 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
| # Rule 2 - Lower | |
| for i in range(2,len(df_grouped)+1): | |
| if df_grouped["x_bar"][i] < df_grouped["-2s"][i] and df_grouped["x_bar"][i-1] < df_grouped["-2s"][i-1]: | |
| R2_lower.append(False) | |
| else: | |
| R2_lower.append(True) | |
| # Rule 2 - Upper | |
| for i in range(2,len(df_grouped)+1): | |
| if df_grouped["x_bar"][i] > df_grouped["+2s"][i] and df_grouped["x_bar"][i-1] > df_grouped["+2s"][i-1]: |
This file contains hidden or 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
| # Rule 1 - Lower | |
| for x in df_grouped['x_bar']: | |
| if x < df_grouped['LCL'][1]: | |
| R1_lower.append(False) | |
| else: | |
| R1_lower.append(True) | |
| # Rule 1 - Upper | |
| for x in df_grouped['x_bar']: | |
| if x > df_grouped['UCL'][1]: |
This file contains hidden or 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
| # Control chart rules lists setup | |
| R1_lower = [] | |
| R1_upper = [] | |
| R2_lower = ['-'] | |
| R2_upper = ['-'] | |
| R3_lower = ['-','-','-','-'] | |
| R3_upper = ['-','-','-','-'] | |
| R4_lower = ['-','-','-','-','-','-','-'] | |
| R4_upper = ['-','-','-','-','-','-','-'] |