Question
Write a Python function list_col(df, col). Its first input is a pandas dataframe. Its second input is a string col that is the name (i.e.,
Write a Python function list_col(df, col). Its first input is a pandas dataframe. Its second input is a string col that is the name (i.e., label) of one of the columns of the dataframe. Your function should return a Python list that contains every unique entry in the column named colin sorted order.
For example, using the justice-centered database and calling its dataframe scdb as we did in examples list_col(scdb, 'chief') should return the list:
['Burger', 'Rehnquist', 'Roberts', 'Vinson', 'Warren']
You may not use any pandas module methods or dataframe or series methods (other than indexing the dataframe by a col, which technically would be considered a dataframe method).
No error checking is required; you may assume that there is an column with name col and that its entries are all of types that can be sorted together. Also, your function does not have to work well on columns with missing or NaN values. (There are pandas isnull() and notnull() series methods that we could use to weed out the missing values, but our goal is to make this a lab that can be done quickly, so we're leaving out that fiddly bit.)
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started