Question: I need a python 3 help people = {name: [Marina, Robert, Mike, Siri, Alexa, Betty], age: [20, 23, 17, 45, 3, 14]} empty_dict = {name:
I need a python 3 help
people = {"name": ["Marina", "Robert", "Mike", "Siri", "Alexa", "Betty"], "age": [20, 23, 17, 45, 3, 14]}
empty_dict = {"name": [], "age": []}
Question 5.1: From Dictionary to Pandas.
Now you need to create a DataFrame from a dictionary passed as an argument:
Note: this will be helpful: Use this link
import pandas as pd
def create_df(dict):
"""Converts dict to a DataFrame
>>> df = create_df(people)
>>> df
name age
0 Marina 20
1 Robert 23
2 Mike 17
3 Siri 45
4 Alexa 3
5 Betty 14
>>> df.sort_values(ascending=False, by='age').iloc[0,:]['name'] 'Siri'
>>> df.sort_values(ascending=True, by='age').iloc[0,:]['name'] 'Alexa'
"""
# Your code is here #
Question 5.2: Filter with pandas
Finally create a function that takes in a dictionary and a threshold and returns only those rows where age is below (or equal to) the given threshold.
Use the function from question 5.
def filter_using_pandas(dict, threshold):
"""Returns data frame with ages below the threshold
>>> nf = filter_using_pandas(people, 23)
>>> nf
name age
0 Marina 20
1 Robert 23
2 Mike 17
4 Alexa 3
5 Betty 14
>>> nf.sort_values(ascending=False, by='age').iloc[0,:]['name'] 'Robert' >>> nf.sort_values(ascending=True, by='age').iloc[0,:]['name'] 'Alexa'
"""
# Your code is here #
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
