-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtask2.py
More file actions
12 lines (11 loc) · 702 Bytes
/
task2.py
File metadata and controls
12 lines (11 loc) · 702 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
#Identify the city with the highest number of restaurants in the dataset.
import pandas as pd
# Load the dataset
df = pd.read_excel('Dataset cognifyz task b.xlsx', sheet_name='Dataset ')
#count the number of restaurants in each city
city_restaurant_count = df.groupby('City')['Restaurant ID'].count()
# Sort the result in descending order to get the city with the most restaurants
city_restaurant_count_sorted = city_restaurant_count.sort_values(ascending=False)
# Display the city with the highest number of restaurants
top_city = city_restaurant_count_sorted.head(1)
print(f"The city with the highest number of restaurants is {top_city.index[0]} with {top_city.values[0]} restaurants.")