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

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!