<jupyter_start><jupyter_text>""""Question 1 : Import CSV fileWrite code to load the alumni csv dataset into a Pandas DataFrame called 'alumni'."""alumni = pd.read_csv('alumni.csv')<jupyter_code>alumni = pd.read_csv('alumni.csv')
alumni.head()<jupyter_output><empty_output><jupyter_text>"""Question 2 : Understand the data setUse the following pandas commands to understand the data set: a) head, b) tail, c) dtypes, d) info, e) describealumni.head() by default we will get the first five rows"""<jupyter_code>alumni.head()<jupyter_output><empty_output><jupyter_text>alumni.tail() by default we will get the first five rows<jupyter_code>alumni.tail()<jupyter_output><empty_output><jupyter_text>getting the data types for each column<jupyter_code>alumni.dtypes<jupyter_output><empty_output><jupyter_text>function to give information of the dataset<jupyter_code>alumni.info()<jupyter_output><class 'pandas.core.frame.DataFrame'>
RangeIndex: 88 entries, 0 to 87
Data columns (total 8 columns):
 #   Column          Non-Null Count  Dtype 
---  ------          --------------  ----- 
 0   Year Graduated  88 non-null     int64 
 1   Gender          88 non-null     object
 2   Marital Status  88 non-null     object
 3   Diploma Type    88 non-null     object
 4   Defaulted       88 non-null     object
 5   Salary          88 non-null     int64 
 6   Fee             88 non-null     int64 
 7   Savings ($)     88 non-null     object
dtypes: int64(3), object(5)
memory usage: 5.6+ KB<jupyter_text>the function to summarize the dataset<jupyter_code>alumni.describe()<jupyter_output><empty_output><jupyter_text>Question 3 : Cleaning the data set - part A Use clean_currency method below to strip out commas and dollar signs from Savings ($) column and put into a new column called 'Savings'."""<jupyter_code>def clean_currency(curr):
    return float(curr.replace(",", "").replace("$", ""))

clean_currency("$66,000")
alumni['Savings']=alumni['Savings ($)'].apply(lambda x: f"{clean_currency(x)}")
alumni
alumni.dtypes.Savings<jupyter_output><empty_output><jupyter_text>Question 4 : Cleaning the data set - part B a) Run the 'alumni["Gender"].value_counts()' to see the incorrect 'M' fields that need to be converted to 'Male'"""<jupyter_code>alumni["Gender"].value_counts()<jupyter_output><empty_output><jupyter_text>b) Now use a '.str.replace' on the 'Gender' column to covert the incorrect 'M' fields. Hint: We must use ^...$ to restrict the pattern to match the whole string.<jupyter_code>alumni['Gender'] = alumni['Gender'].str.replace('^M$','Male',regex=True)
alumni["Gender"].value_counts()<jupyter_output><empty_output><jupyter_text>Question 5 : Working with the data set (4) a) get the median, b) mean and c) standard deviation for the 'Salary' column"""<jupyter_code>alumni['Salary'].median()
alumni['Salary'].mean()
alumni['Salary'].std()<jupyter_output><empty_output><jupyter_text>b)identify which alumni paid more than $15000 in fees, using the 'Fee' column<jupyter_code>paid_above_15000 = alumni[alumni["Fee"] >15000]
paid_above_15000.head()<jupyter_output><empty_output><jupyter_text>Question 6 : Visualise the data set a) Using the 'Diploma Type' column, plot a bar chart and show its value counts<jupyter_code>alumni['Diploma Type'].value_counts().plot(kind='bar')<jupyter_output><empty_output><jupyter_text>b) Now create a box plot comparison between 'Savings' and 'Salary' columns<jupyter_code>sns.boxplot(x='Salary',y='Savings',data=alumni)<jupyter_output><empty_output><jupyter_text>c) Generate a histogram with the 'Salary' column and use 12 bins.<jupyter_code>sns.histplot(data=alumni,x='Salary',bins=12)<jupyter_output><empty_output><jupyter_text>d) Generate a scatter plot comparing 'Salary' and 'Savings' columns.<jupyter_code>sns.catplot(x="Salary", y="Savings", data=alumni)<jupyter_output><empty_output><jupyter_text>Using both the 'Marital Status' and 'Defaulted' create a contingency table. Hint: crosstab<jupyter_code>Contigency = pd.crosstab(alumni['Marital Status'],alumni['Defaulted'])
print(Contigency)<jupyter_output>Defaulted       No  Yes
Marital Status         
Divorced         8   11
Married         19   16
Single           9   25
{'fraction_non_alphanumeric': 0.1259899208063355, 'fraction_numerical': 0.021118310535157187, 'mean_word_length': 5.402457757296467, 'pattern_counts': {'":': 0, '<': 64, '<?xml version=': 0, '>': 65, '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': '16', 'dir': 'jupyter-structured-clean-dedup', 'id': '524202', 'license': 'MIT', 'n_tokens_mistral': 1534, 'n_tokens_neox': 1395, 'n_words': 359, 'path': 'Pandas Assignment_1 (2).ipynb', 'repo_name': 'Lissah2016/Pandas-Assignement_1', 'size': '4167'}