Page 242 - Touhpad Ai
P. 242
21 st
Century #Coding & Computational Thinking
Skills
1. Use the given data to perform the following data transformation tasks:
a. Change the format of Date_of_Joining to DD-MM-YYYY using Pandas.
b. Convert the distance from miles to kilometers (1 mile = 1.60934 km) and add it as a new column.
c. Encode the Response column as 1 for Yes and 0 for No.
d. Handle missing values in the Score column by filling them with the average score.
e. (Bonus) Create a new column called Year_of_Joining by extracting the year from the Date_of_
Joining.
Sample dataset:
import pandas as pd
data = {
'Name': ['Harish', 'Ritu', 'Sapna', 'Asha'],
'Date_of_Joining': ['12/07/2023', '15/09/2023', '01/08/2023', '10/10/2023'],
'Distance_to_Office (miles)': [5.3, 3.4, 6.7, 4.3],
'Response': ['Yes', 'No', 'Yes', 'No'],
'Score': [92, None, 87, None]
}
df = pd.DataFrame(data)
print(df)
2. Using the sample data given below, perform standardization methods learnt in the chapter.
import pandas as pd
data = {
'Name': ['Shagun', 'Nandini', 'yatharth', 'nysa', 'ANIL'],
'Score': [65, 80, 75, 95, 85],
'Weight_pounds': [115, 145, 153, 135, 126],
'Response': ['YES', 'no', 'y', 'No', 'nO'],
'Joining_Date': ['2023/07/12', '15-08-2023', '2023.09.01', '10-10-2023',
'2023/11/05'],
'Salary': [30800, 45200, 50005, 42080, 35063]
}
df = pd.DataFrame(data)
print(df)
Answers
Exercise
A. 1. c 2. a 3. b 4. c 5. a 6. b 7. b 8. b 9. d 10. b 11. c 12. c
B. 1. Series, DataFrame 2. NumPy 3. Shape 4. Kaggle 5. Lower 6. List, NumPy array
7. Series 8. Datetime 9. Data transformation 10. Data standardisation
C. 1. False 2. True 3. False 4. True 5. True 6. True
7. True 8. False 9. True 10. True
240 Touchpad Artificial Intelligence - XI

