Open sandeepny441 opened 1 year ago
Sample data
import pandas as pd
data = { 'Shop_Name': ['Starbucks', 'Blue Bottle', 'Dunkin', 'Peets', 'Starbucks', 'La Colombe', 'Blue Bottle', 'Peets', 'Starbucks', 'Dunkin'], 'Location': ['Hollywood', 'San Diego', 'San Diego', 'Hollywood', 'New York', 'New York', 'Hollywood', 'San Diego', 'New York', 'Hollywood'], 'Rating': [4.5, 4.7, 4.1, 4.3, 4.5, 4.8, 4.6, 4.2, 4.4, 3.9], 'Type': ['Chain', 'Independent', 'Chain', 'Chain', 'Chain', 'Independent', 'Independent', 'Chain', 'Chain', 'Chain'] }
coffee_shops = pd.DataFrame(data)
yeah updated the Question section along with data
import pandas as pd
data = { 'Shop_Name': ['Starbucks', 'Blue Bottle', 'Dunkin', 'Peets', 'Starbucks', 'La Colombe', 'Blue Bottle', 'Peets', 'Starbucks', 'Dunkin'], 'Location': ['Hollywood', 'San Diego', 'San Diego', 'Hollywood', 'New York', 'New York', 'Hollywood', 'San Diego', 'New York', 'Hollywood'], 'Rating': [4.5, 4.7, 4.1, 4.3, 4.5, 4.8, 4.6, 4.2, 4.4, 3.9], 'Type': ['Chain', 'Independent', 'Chain', 'Chain', 'Chain', 'Independent', 'Independent', 'Chain', 'Chain', 'Chain'] }
coffee_shops = pd.DataFrame(data)
================================================================
Question 1: How do you group the coffee_shops DataFrame by 'Location', and calculate the average 'Rating' for each 'Location'?
Question 2: After grouping coffee_shops by 'Shop_Name', how do you get the group corresponding to 'Starbucks'?
Question 3: How can you find the number of shops in each 'Location' by using groupby and size?
Question 4: How can you iterate over groups obtained by grouping coffee_shops by 'Type', and print out each group's data?