Centurion University**We aren't endorsed by this school
Course
CSE CUTM1018
Subject
Computer Science
Date
Dec 20, 2024
Pages
6
Uploaded by MajorFlagPony56
Data Analysis & Visualization Case Study 2 : Report Submitted By : Sohom Ghorai 190301120001 B.Tech CSE , 3rdSem CUTM , BBSR
Used Dataset : Olympic 2012 Medal Tally.xlsx Given Problems : 1.Find and print the name of the country that won maximum gold medals 2.Find and print the countries who won more than 20 gold medals 3.Find and print the countries who won least number of total medal 4.Print each country name with corresponding number of gold medal and total medal. For Ex “Individual country name, total gold medal, total medal”5.Draw a suitable graph to represent all data Sollutions : 1. Find and print the name of the country that won maximum gold medals Code import numpy as np import pandas as pd import warnings warnings.filterwarnings('ignore') df = pd.read_excel(r"C:\Users\Sohom Rik\Downloads\Case 2_Olympic\Case 2\Olympic 2012 Medal Tally.xlsx",sheet_name='Sheet1',skiprows = [1,2]) arrCountries = np.array(df['Unnamed: 1']) arrCountriesCode = np.array(df['Unnamed: 2']) arrCountriesWonYear = np.array(df['Unnamed: 3'])
arrCountriesWonTotalGold = np.array(df['Unnamed: 4']) arrCountriesWonTotalSilver = np.array(df['Unnamed: 5']) arrCountriesWonTotalBronze = np.array(df['Unnamed: 6']) #Country having highest gold medals highestCountryGoldIndex = arrCountriesWonTotalGold.argmax() arrCountries[highestCountryGoldIndex] Output: 'United States' In [4]: So United States is the nation to have maximum number of gold medals. 2.Find and print the countries who won more than 20 gold medalsCode: #Countries having more than 20 gold arrCountriesMoreThan20Gold = arrCountries[arrCountriesWonTotalGold > 20] for countryName in arrCountriesMoreThan20Gold: print(countryName) Output : Great Britain China Russia United States 3.Find and print the countries who won least number of total medal Code : #Least medal country df['Total']=df.iloc[:,4:].sum(axis=1) df
leastnumberoftotalmedal = df['Total'].argmin() arrCountries[leastnumberoftotalmedal] Output : 'Korea' 4.Print each country name with corresponding number of gold medal and total medal. For Ex “Individual country name, total gold medal, total medal”Code : #Individual medal tally of countries print ("{:<20} {:<10} {:<10}".format('Country','Golds','Total Medals')) for index,country in enumerate(arrCountries): totalMedals = (arrCountriesWonTotalGold[index]+arrCountriesWonTotalSilver[index]+arrCountriesWonTotalBronze[index]); print ("{:<20} {:<10} {:<10}".format(country,arrCountriesWonTotalGold[index],totalMedals)) Output : Country Golds Total Medals Great Britain 29 65 China 38 88 Russia 24 81 United States 46 103 Korea 13 28 Japan 7 38 Germany 11 36
5.Draw a suitable graph to represent all data Code: df = pd.read_excel(r"C:\Users\Sohom Rik\Downloads\Case 2_Olympic\Case 2\Olympic 2012 Medal Tally.xlsx",sheet_name='Sheet1',skiprows = [1,2]) df=df.dropna(axis=1) df.columns=['Country','Country_code','Year','Gold','Silver','Bronze'] del df['Country_code'] del df['Year'] df Country Gold Silver Bronze 0 Great Britain 29 17 19 1 China 38 28 22 2 Russia 24 25 32 3 United States 46 28 29 4 Korea 13 8 7 5 Japan 7 14 17 6 Germany 11 11 14 import plotly.express as px fig = px.bar(df, x="Country", y=["Gold","Silver","Bronze"]) fig.update_layout(title_text='Complete Graphical Data',title_x=0.5, yaxis_title="Medal Count") fig.update_layout(legend_title_text='Medals')