Question
Can anyone please help with my Python problem? Exercise #1 name: average_price_by_section arguments: *df:PandasDataFramerepresentingalist of grocerystoreitems *section: String representingasection of thegrocerystore returns: float representingthemeanpriceoftheitems in
Can anyone please help with my Python problem?
Exercise #1
name:
average_price_by_section
arguments:
*df:PandasDataFramerepresentingalistofgrocerystoreitems *section:Stringrepresentingasectionofthegrocerystore
returns:
floatrepresentingthemeanpriceoftheitemsinthegivensection UsetheDataFramegiveninthecellbelow
grocery_items = pd.DataFrame({
'item_name': ['butter', 'milk', 'eggs', 'bread', 'dinner_rolls', 'toothpaste', 'shampoo', 'sugar', 'oatmeal', 'cereal'],
'price': [6.5, 4.5, 3, 4, 5, 7, 10, 5.4, 2.5, 5.25],
'stock': [10, 20, 40, 55, 22, 10, 32, 40, 1, 9],
'section': ['dairy', 'dairy', 'dairy', 'bread', 'bread', 'toiletries', 'toiletries', 'baking', 'pantry', 'pantry'],
'perishable': [True, True, True, True, True, False, False, False, False, False]
})
### average_price_by_section goes here
assert average_price_by_section(grocery_items, 'baking') == 5.4
assert average_price_by_section(grocery_items, 'toiletries') == 8.5
assert average_price_by_section(grocery_items, 'bread') == 4.5
Thank you!
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