Name the function extract_title. It must take any Pandas DataFrame as input and return a DataFrame as output with an additional Title column. Assume that input_df represents a DataFrame possessing a Name column, with each corresponding row entry being a string-based name containing exactly one title. Assume that a title is represented by a word with two or more characters ending in a period. Hint: you can import re and use a regular expression search (re.search()) to find the title in each name.
START FUNCTION def extract_title(input_df):
# your code here
return
END FUNCTION
extract_title(train_df).head()
PassengerId Survived Pclass \
Name
Braund, Mr. Owen Harris male 22.0 A5
Cumings, Mrs. John Bradley (Florence Briggs Thayer) female 38.0 PC 17599
Heikkinen, Miss. Laina female 26.0 STON/O2
Futrelle, Mrs. Jacques Heath (Lily May Peel) female 35.0 113803
Allen, Mr. William Henry male 35.0 373450
Fare Cabin Embarked \
Name
Braund, Mr. Owen Harris 7.2500 NaN S
Cumings, Mrs. John Bradley (Florence Briggs Thayer) 71.2833 C85 C
Heikkinen, Miss. Laina 7.9250 NaN S
Futrelle, Mrs. Jacques Heath (Lily May Peel) 53.1000 C123 S
Allen, Mr. William Henry 8.0500 NaN S
Title
Name
Braund, Mr. Owen Harris Mr
Cumings, Mrs. John Bradley (Florence Briggs Thayer) Mrs
Heikkinen, Miss. Laina Miss
Futrelle, Mrs. Jacques Heath (Lily May Peel) Mrs
Allen, Mr. William Henry Mr