Answered step by step
Verified Expert Solution
Question
1 Approved Answer
8.16 Week 10 (Halloween) Lab: Practice with lists and pandas Learning Objectives: Working with lists, understanding how tools are made How did pandas get built?
8.16 Week 10 (Halloween) Lab: Practice with lists and pandas Learning Objectives: Working with lists, understanding how tools are made How did pandas get built? What do we do if we need some functionality that is not in it? In this lab, we'll get a taste of the answers. Directions Write a Python function list_col (df, col). Its first input is a pandas dataframe. Its second input is a sting 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 col in sorted order. (As always, a docstring and meaningful variable names are required) 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: I'Burger',Rehnquist', Roberts','VinsonWarren' You may not use any pandas module methods or dataframe or series methods (other than indexing the dataframe by a col, or by using.loc or iloc, though probably you would be better off not using loc or .iloc) No error checking is required; you may assume that there is an column with narme 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 pandasisnull() and notnull() series methods that we apuld 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.) Remarks You can write a Python for loop over a Pandas series (i.e., dataframe column) that works exactly like for loops over strings and lists Depending on how you go about this problem, you might find one or both of the boolean operators in and not useful You will want to test your function. Fortunately for you, you have experience working with reading a csv file into a pandas dataframe, so you should be able to find some test cases
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