<SYSTEM_TASK:>
Given the following text description, write Python code to implement the functionality described below step by step
<END_TASK>
<USER_TASK:>
Description:
 <a href='http
Step1:  TASK
Step2:  TASK
Step3:  TASK
Step4:  TASK
Step5:  TASK
Step6:  TASK
Step7:  TASK
Step8:  TASK
Step9:  TASK
Step10:  TASK
Step11:  TASK
Step12:  TASK
<ASSISTANT_TASK:>
Python Code:
# CODE HERE
import pandas as pd
Explanation: <a href='http://www.pieriandata.com'><img src='../Pierian_Data_Logo.png'/></a>
<center><em>Copyright Pierian Data</em></center>
<center><em>For more information, visit us at <a href='http://www.pieriandata.com'>www.pieriandata.com</a></em></center>
Pandas Exercises - Solutions
TASK: Import pandas
End of explanation
df = pd.read_csv('bank.csv')
Explanation: TASK:  Read in the bank.csv file that is located under the 01-Crash-Course-Pandas folder. Pay close attention to where the .csv file is located! Please don't post to the QA forums if you can't figure this one out, instead, run our solutions notebook directly to see how its done.
End of explanation
# CODE HERE
df.head()
Explanation: TASK: Display the first 5 rows of the data set
End of explanation
# CODE HERE
df['age'].mean()
Explanation: TASK: What is the average (mean) age of the people in the dataset?
End of explanation
# CODE HERE
df['age'].idxmin()
df.iloc[503]['marital']
Explanation: TASK: What is the marital status of the youngest person in the dataset?
HINT
End of explanation
# CODE HERE
df['job'].nunique()
Explanation: TASK: How many unique job categories are there?
End of explanation
# CODE HERE
df['job'].value_counts()
Explanation: TASK: How many people are there per job category? (Take a peek at the expected output)
End of explanation
#CODE HERE
# Many, many ways to do this one! Here is just one way:
100*df['marital'].value_counts()['married']/len(df)
# df['marital].value_counts()
Explanation: TASK: What percent of people in the dataset were married?
End of explanation
df['default code'] = df['default'].map({'no':0,'yes':1})
df.head()
Explanation: TASK: There is a column labeled "default". Use pandas' .map() method to create a new column called "default code" which contains a 0 if there was no default, or a 1 if there was a default. Then show the head of the dataframe with this new column.
Helpful Hint Link One
Helpful Hint Link Two
End of explanation
# CODE HERE
df['marital code'] = df['marital'].apply(lambda status: status[0])
df.head()
Explanation: TASK: Using pandas .apply() method, create a new column called "marital code". This column will only contained a shortened code of the possible marital status first letter. (For example "m" for "married" , "s" for "single" etc... See if you can do this with a lambda expression. Lots of ways to do this one!
Hint Link
End of explanation
# CODE HERE
df['duration'].max()
Explanation: TASK: What was the longest lasting duration?
End of explanation
# CODE HERE
df[df['job']=='unemployed']['education'].value_counts()
Explanation: TASK: What is the most common education level for people who are unemployed?
End of explanation
# CODE HERE
df[df['job']=='unemployed']['age'].mean()
Explanation: TASK: What is the average (mean) age for being unemployed?
End of explanation
<END_TASK>