<jupyter_start><jupyter_text>External Lab  Part-1  About the datasetThis is perhaps the best known database to be found in the pattern recognition literature. The data set contains 3 classes of 50 instances each, where each class refers to a type of iris plant.  One class is linearly separable from the other 2; the latter are NOT linearly separable from each other.Attribute Information:   1. sepal length in cm   2. sepal width in cm   3. petal length in cm   4. petal width in cm   5. class:       -- Iris Setosa      -- Iris Versicolour      -- Iris Virginica  Read the dataset and store it in the dataframe named Iris<jupyter_code>import pandas as pd
import numpy as np
import matplotlib.pyplot as plt

iris=pd.read_csv('C://Users/sande\\Desktop\\h20\\AIML\\Residency-1\\Lab_external\\iris.csv')<jupyter_output><empty_output><jupyter_text>Find out the datatypes of each and every column<jupyter_code>print("Data Types in each column in iris DataSet is :\n")
iris.dtypes<jupyter_output>Data Types in each column in iris DataSet is :<jupyter_text>Print top 10 & bottom 10 samples from the dataframe<jupyter_code>#printing top ten rows and columns in dataset using DataFrame.head() and DataFrame.tail()
print("The top 10 rows :\n")
iris.head(10)

print("The bottom 10 rows :\n")
iris.tail(10)<jupyter_output>The bottom 10 rows :<jupyter_text>Find the shape of the dataset<jupyter_code>#Using DataFrame.shape we can print the shape of the data frame
print(iris.shape)<jupyter_output>(150, 5)<jupyter_text>Set the index of the dataframe to be the first column<jupyter_code># We can set the index of the dataframe using DataFrame.index=DataFrame['Column_name']
iris.index=iris['Sepal Length (in cm)']
#We can notice that sepal length (in cm) is the index 
iris.head()<jupyter_output><empty_output><jupyter_text>Use iloc function to print all the rows of the 3rd column<jupyter_code>#We can using iloc to print all rows in 3rd column as DataFrame.iloc[[:],[:]
#We can print the petal length the 3rd column and index(sepal length)
iris.iloc[:,[2]]<jupyter_output><empty_output><jupyter_text>SlicingPrint only the Sepal width and Sepal Length for first 10 rows<jupyter_code># We can use slicing to print Sepal width and sepal length
iris.columns
iris.iloc[:10,[1,0]]<jupyter_output><empty_output><jupyter_text>Using Logical statements for indexingPrint all the columns of row which has class name "Iris-setosa"<jupyter_code># All Columns with class name "Iris-setosa"
iris[iris['Class']=='Iris-setosa']<jupyter_output><empty_output><jupyter_text>Multiply Sepal Length and width and store it under the column name "SepalExtra" in the same Iris dataframe<jupyter_code># A new SepalExtra Column with product of Sepal length and Sepal Width
iris['SepalExtra']=iris['Sepal Length (in cm)']*iris['Sepal Width in (cm)']
# Displaying Sepal length , Sepal Width and SepalExtra using DataFrame.loc
iris.loc[:,['Sepal Length (in cm)','Sepal Width in (cm)','SepalExtra']]<jupyter_output><empty_output><jupyter_text>Find out the mean and variance for each column but for class column<jupyter_code># By specifying numeric only will not include string type data
print(iris.mean(numeric_only=True))<jupyter_output>Sepal Length (in cm)     5.843333
Sepal Width in (cm)      3.054000
Petal length (in cm)     3.758667
Petal width (in cm)      1.198667
SepalExtra              17.806533
dtype: float64<jupyter_text>Write a function that accepts two numbers as input and prints them - Pass the Sepal length and sepal width of 5th row and print the output<jupyter_code>def printer(a,b):
    print("The Accepted two numbers are \n")
    print(a,'\t',b)
printer(iris.iloc[4,0],iris.iloc[4,1])<jupyter_output>The Accepted two numbers are 

5.0 	 3.6<jupyter_text>Find the range of all the columns in the dataset*Range = Max value - Min value (in the column)*<jupyter_code>print("Range of Sepal Length (in cm)\t:",max(iris['Sepal Length (in cm)']-min(iris['Sepal Length (in cm)'])))
print("Range of 'Sepal Width in (cm)'\t:",max(iris['Sepal Width in (cm)']-min(iris['Sepal Width in (cm)'])))
print("Range of 'Petal length (in cm)'\t:",max(iris['Petal length (in cm)']-min(iris['Petal length (in cm)'])))
print("Range of 'Petal width (in cm)'\t:",max(iris['Petal width (in cm)']-min(iris['Petal width (in cm)'])))
print("Range of 'SepalExtra'\t:",max(iris['SepalExtra']-min(iris['SepalExtra'])))<jupyter_output>Range of Sepal Length (in cm)	: 3.6000000000000005
Range of 'Sepal Width in (cm)'	: 2.4000000000000004
Range of 'Petal length (in cm)'	: 5.9
Range of 'Petal width (in cm)'	: 2.4
Range of 'SepalExtra'	: 20.02<jupyter_text>Sort the entire dataset according to the column Petal width<jupyter_code>#Soring based on Petal Width (in cm)
iris.sort_values(by='Petal width (in cm)')<jupyter_output><empty_output><jupyter_text>Remove the new column "SepalExtra" from the dataframe<jupyter_code>#Using Drop and specifying the column name we can remove the SepalExtra from iris DataDrame
iris.drop(columns=['SepalExtra'])<jupyter_output><empty_output><jupyter_text>Take only the top 10 rows of the dataset with only first 3 columns and store it in a dataframe named "IrisSubset"<jupyter_code>#Storing the subset dataframe in IrisSubset
IrisSubset=iris.iloc[:10,:3]
IrisSubset<jupyter_output><empty_output><jupyter_text>Part-2  The dataset HR contains information collected from the survey floated by a HR within the company.As a part of this lab, you are expected to answer the below questions  Import numpy and Pandas<jupyter_code>import numpy as np
import pandas as pd<jupyter_output><empty_output><jupyter_text>Import the dataset (Note: The dataset is in .txt format) - Make sure to use delimiters<jupyter_code>Hr= pd.read_csv('C://Users/sande\\Desktop\\h20\\AIML\\Residency-1\\Lab_external\\HR_external.txt', sep="\t")<jupyter_output><empty_output><jupyter_text>Print the no of rows and columns in the dataset<jupyter_code>#The number of rows are using len(DataFrame.index)
len(Hr.index)
#The number of rows are using len(DataFrame.columns)
len(Hr.columns)<jupyter_output><empty_output><jupyter_text>Find out the type of each and every column in the dataset<jupyter_code>Hr.dtypes<jupyter_output><empty_output><jupyter_text>Print out all the rows from 3rd column to 10th columns<jupyter_code>#We can print all the rows from 3rd column to 10th column
Hr.iloc[:,2:10]<jupyter_output><empty_output><jupyter_text>Find out the no of male & female employees in the company*Hint: Use can use a condition to find out the no of 1s and 0s in gender and sum it*<jupyter_code>#Using len and condition we can find the number of males in the company
print("Number of Males in the company\t",len(Hr[Hr['Gender']==1]))
#Using len and condition we can find the number of females in the company
print("Number of females in the company\t",len(Hr[Hr['Gender']==2]))<jupyter_output>Number of females in the company	 588<jupyter_text>Find out the IQR for the column - Age *Hint: IQR - Interquartile range = 75th percentile - 25th percentile*<jupyter_code>print("IQR of Age Attribute in the DataFrame is \t",Hr['Age'].quantile(q=0.75)-Hr['Age'].quantile(q=0.25))<jupyter_output>IQR of Age Attribute in the DataFrame is 	 13.0<jupyter_text>Find out the mean, median and variance for the column - DailyRate<jupyter_code>print("Mean of DailyRate Attribute in DataFrame\t",Hr['DailyRate'].mean())
print("Median of DailyRate Attribute in DataFrame\t",Hr['DailyRate'].median())
print("Variance of DailyRate Attribute in DataFrame\t",Hr['DailyRate'].var())<jupyter_output>Mean of DailyRate Attribute in DataFrame	 802.4857142857143
Median of DailyRate Attribute in DataFrame	 802.0
Variance of DailyRate Attribute in DataFrame	 162819.59373723628<jupyter_text>Plot the attrition column (Since it is a categorical variable, chose the plot accordingly)<jupyter_code>import seaborn as sns
sns.countplot(x='Attrition', hue='MaritalStatus', data=Hr)
#After considering many visualizations , on sensible inference is that , people with Marital Status as 1 have left the company in a good number
#And people with marital status as 2 are the one's who are still in the firm
#Other Approach using SubSets of Attrition 
y_e_s = Hr[Hr['Attrition']=='Yes'] #subset Attrition = Yes
n_o = Hr[Hr['Attrition']=='No'] ##subset Attrition = No
sns.countplot(x='Department', hue='Gender', data=y_e_s)
#We can Understand people from 3rd Department are leaving the firm
plt.show()<jupyter_output><empty_output><jupyter_text>Plot Total working years using matplotlib plot function<jupyter_code>plt.plot(Hr['TotalWorkingYears'])<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.10200512940079273, 'fraction_numerical': 0.02436465376544649, 'mean_word_length': 5.997553017944535, 'pattern_counts': {'":': 0, '<': 92, '<?xml version=': 0, '>': 92, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 2, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '25', 'dir': 'jupyter-structured-clean-dedup', 'id': '480492', 'license': 'MIT', 'n_tokens_mistral': 3039, 'n_tokens_neox': 2840, 'n_words': 971, 'path': 'Statistical_Analysis_Attrition_Dataset.ipynb', 'repo_name': 'swaroop9ai9/Learning-development', 'size': '8578'}