Skip to content

Commit 03ef389

Browse files
authored
UniversityRankingsPythonScript (DhanushNehru#397)
Adding University Rankings Python project to repository. This program ranks universities in its respective order using data from .csv files and incorporates location attributes such as continent, country, and capital.
1 parent b176557 commit 03ef389

File tree

5 files changed

+212
-0
lines changed

5 files changed

+212
-0
lines changed

README.md

+1
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,7 @@ More information on contributing and the general code of conduct for discussion
141141
| Turtle Graphics | [Turtle Graphics](https://github.com/DhanushNehru/Python-Scripts/tree/master/Turtle%20Graphics) | Code using turtle graphics. |
142142
| Twitter Selenium Bot | [Twitter Selenium Bot](https://github.com/DhanushNehru/Python-Scripts/tree/master/Twitter%20Selenium%20Bot) | A bot that can interact with Twitter in a variety of ways. |
143143
| Umbrella Reminder | [Umbrella Reminder](https://github.com/DhanushNehru/Python-Scripts/tree/master/Umbrella%20Reminder) | A reminder for umbrellas. |
144+
| University Rankings | [University Rankings](https://github.com/DhanushNehru/Python-Scripts/tree/master/University%20Rankings) | Ranks Universities across the globes using the Country, Continent, and Captial |
144145
| URL Shortener | [URL Shortener](https://github.com/DhanushNehru/Python-Scripts/tree/master/URL%20Shortener) | A URL shortener code compresses long URLs into shorter, more manageable links |
145146
| Video Downloader | [Video Downloader](https://github.com/DhanushNehru/Python-Scripts/tree/master/Video%20Downloader) | Download Videos from youtube to your local system. |
146147
| Video Watermarker | [Video Watermarker](https://github.com/DhanushNehru/Python-Scripts/tree/master/Video%20Watermarker) | Adds watermark to any video of your choice. |

University Rankings/README.md

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
# UniversityRankings
2+
A program that I constructed for ranking universities based on two files provided by the user. One would contain the list of universities around the world ranked in order, and another file contains the various countries and its corresponding capital. In this instance, I used two files called capitals.csv and TopUni.csv. I chose to create this program by using one function, however, this program can be altered and constructed by using multiple functions. Since the files that we are using are comma separated values (csv), I chose to open them by importing and using pandas as pd. The output was displayed on an output.txt file to record my output in that file. Below are the following calculations that were made in the program.
3+
4+
1. The first part of the program details the total number of universities in the TopUni.csv file.
5+
2. The second part of the program displays all the available countries
6+
3. The third part of the program illustrates all the available continents
7+
4. The next part of the program identifies the international and national rankings that are associated with the selected country
8+
5. The following portion of the code calculates the average score, relative score,
9+
6. The next part determines the capital of the selected country
10+
7. The last part of the code outputs the universities name(s) that contain the capital

University Rankings/output.txt

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+

University Rankings/pyvenv.cfg

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
home = /Library/Frameworks/Python.framework/Versions/3.10
2+
implementation = CPython
3+
version_info = 3.10.0.final.0
4+
virtualenv = 20.13.0
5+
include-system-site-packages = false
6+
base-prefix = /Library/Frameworks/Python.framework/Versions/3.10
7+
base-exec-prefix = /Library/Frameworks/Python.framework/Versions/3.10
8+
base-executable = /usr/local/bin/python3.10

University Rankings/univRanking.py

+192
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,192 @@
1+
import pandas as pd
2+
3+
def getInformation(selectedCountry, rankingFileName, capitalsFileName):
4+
# add selected country
5+
# Total number of universities
6+
# show countries
7+
# show continents
8+
# calculate average score (sum of all uni scores within the selected country) / (number of universities within the selected country)
9+
# display the average score
10+
# calculate the relative score (average score) / (The highest score within the continent where the university is selected)
11+
12+
available_countries = 0
13+
counter = 0
14+
countries = ""
15+
continents = ""
16+
countries_lst = []
17+
continents_lst = []
18+
TopUni = pd.read_csv(rankingFileName)
19+
Capitals = pd.read_csv(capitalsFileName)
20+
country_counter = 0
21+
country_counter_rank = 1
22+
23+
file = open("output.txt", "w") # open output.txt file where output is stored
24+
25+
for line in range(len(TopUni)):
26+
counter += 1
27+
28+
file.write("Total number of Universities => {}\n" .format(counter)) # PART 1 TOTAL NUMBER OF UNIVERSITIES
29+
30+
# LISTING ALL AVAILABLE COUNTRIES WITHIN THE FILE
31+
for country in Capitals["Country Name"]:
32+
if country not in countries_lst:
33+
countries_lst.append(country)
34+
available_countries += 1
35+
36+
for country in countries_lst:
37+
if countries == "":
38+
countries = countries + country
39+
else:
40+
countries = countries + ", " + country
41+
42+
file.write("Available countries => {}\n" .format(countries)) # PART 2 AVAILABLE COUNTRIES
43+
44+
# FINDING ALL AVAILABLE CONTINENTS WITHIN THE FILE
45+
for continent in Capitals["Continent"]:
46+
if continent not in continents_lst:
47+
continents_lst.append(continent)
48+
49+
for continent in continents_lst:
50+
if continents == "":
51+
continents = continents + continent
52+
else:
53+
continents = continents + ", " + continent
54+
55+
file.write("Available Continents => {}\n" .format(continents)) # PART 3 AVAILABLE CONTINENTS
56+
57+
# FINDING THE INTERNATIONAL RANK OF COUNTRIES ASSOCIATED WITH THE SELECTED COUNTRY
58+
for country in TopUni["Country"]:
59+
if country == selectedCountry:
60+
file.write("At international rank => {} the university name is => {}\n" .format(country_counter_rank, TopUni["Institution name"][country_counter])) # PART 4 INTERNATIONAL RANK
61+
country_counter += 1
62+
country_counter_rank += 1
63+
64+
country_counter = 0
65+
country_national_counter_rank = 1
66+
67+
for country in TopUni["Country"]:
68+
if country == selectedCountry:
69+
file.write("At national rank => {} the university name is => {}\n" .format(country_national_counter_rank, TopUni["Institution name"][country_counter])) # PART 5 NATIONAL RANK
70+
country_national_counter_rank += 1
71+
country_counter += 1
72+
73+
number_of_universities = 0
74+
university_score = 0
75+
TopUni = pd.read_csv(rankingFileName)
76+
counter = 0
77+
78+
for country in TopUni["Country"]:
79+
if selectedCountry == country:
80+
university_score += TopUni["Score"][counter]
81+
number_of_universities += 1
82+
counter += 1
83+
84+
# THE AVERAGE SCORE CALCULATIONS
85+
averageScore = university_score / number_of_universities
86+
file.write("The average score => {}%\n" .format(round(averageScore, 1))) # PART 6 AVERAGE SCORE # PART 6
87+
88+
number_of_universities = 0
89+
university_score = 0
90+
TopUni = pd.read_csv(rankingFileName)
91+
Capitals = pd.read_csv(capitalsFileName)
92+
highestScore1 = 0
93+
highestScore2 = 0
94+
highestScore3 = 0
95+
highestScore4 = 0
96+
highestScore5 = 0
97+
counter1 = 0
98+
counter2 = 0
99+
counter3 = 0
100+
continent = ""
101+
102+
# CALCULATING THE RELATIVE SCORE
103+
for country in TopUni["Country"]:
104+
if selectedCountry == country:
105+
university_score += TopUni["Score"][counter1]
106+
number_of_universities += 1
107+
counter1 += 1
108+
109+
averageScore = university_score / number_of_universities
110+
111+
for country in Capitals["Country Name"]:
112+
if selectedCountry == country:
113+
continent = Capitals["Continent"][counter2]
114+
counter2 += 1
115+
116+
for continentScore in TopUni["Score"]:
117+
if TopUni["Country"][counter3] in ["Jordan", "Palestine", "China", "Israel", "Japan", "Singapore", "South Korea", "Taiwan"]:
118+
if continentScore > highestScore1:
119+
highestScore1 = continentScore
120+
elif TopUni["Country"][counter3] in "Australia":
121+
if continentScore > highestScore2:
122+
highestScore2 = continentScore
123+
elif TopUni["Country"][counter3] in ["Canada", "USA"]:
124+
if continentScore > highestScore3:
125+
highestScore3 = continentScore
126+
elif TopUni["Country"][counter3] in ["Denmark", "France", "Germany", "Netherlands", "Norway", "Sweden", "Switzerland", "United Kingdom"]:
127+
if continentScore > highestScore4:
128+
highestScore4 = continentScore
129+
elif TopUni["Country"][counter3] in ["Egypt"]:
130+
if continentScore > highestScore5:
131+
highestScore5 = continentScore
132+
133+
counter3 += 1
134+
135+
# PART 7 RELATIVE SCORE
136+
if selectedCountry in ["Jordan", "Palestine", "China", "Israel", "Japan", "Singapore", "South Korea", "Taiwan"]:
137+
relativeScore = (averageScore / highestScore1) * 100
138+
file.write("The relative score to the top university in {} is => ({} / {}) x 100% = {}%\n" .format(continent, averageScore, highestScore1, round(relativeScore, 1)))
139+
elif selectedCountry in "Australia":
140+
relativeScore = (averageScore / highestScore2) * 100
141+
file.write("The relative score to the top university in {} is => ({} / {}) x 100% = {}%\n" .format(continent, averageScore, highestScore2, round(relativeScore, 1)))
142+
elif selectedCountry in ["Canada", "USA"]:
143+
relativeScore = (averageScore / highestScore3) * 100
144+
file.write("The relative score to the top university in {} is => ({} / {}) x 100% = {}%\n" .format(continent, averageScore, highestScore3, round(relativeScore, 1)))
145+
elif selectedCountry in ["Denmark", "France", "Germany", "Netherlands", "Norway", "Sweden", "Switzerland", "United Kingdom"]:
146+
relativeScore = (averageScore / highestScore4) * 100
147+
file.write("The relative score to the top university in {} is => ({} / {}) x 100% = {}%\n" .format(continent, averageScore, highestScore4, round(relativeScore, 1)))
148+
elif selectedCountry in ["Egypt"]:
149+
relativeScore = (averageScore / highestScore5) * 100
150+
file.write("The relative score to the top university in {} is => ({} / {}) x 100% = {}%\n" .format(continent, averageScore, highestScore5, round(relativeScore, 1)))
151+
152+
# FINDING THE CAPITAL OF THE SELECTED COUNTRY
153+
Capitals = pd.read_csv(capitalsFileName)
154+
capital = ""
155+
counter = 0
156+
157+
for cap in Capitals["Country Name"]:
158+
if cap == selectedCountry:
159+
capital = Capitals["Capital"][counter]
160+
counter += 1
161+
162+
file.write("The capital is => {}\n" .format(capital)) # PART 8 CAPITAL OF SELECTED COUNTRY
163+
164+
# FINDING THE UNIVERSITIES THAT HAVE THE NAME OF THE CAPITAL WITHIN IT
165+
TopUni = pd.read_csv(rankingFileName)
166+
Capitals = pd.read_csv(capitalsFileName)
167+
capital = ""
168+
counter1 = 0
169+
counter2 = 0
170+
number_counter = 1
171+
for cap in Capitals["Country Name"]:
172+
if cap == selectedCountry:
173+
capital = Capitals["Capital"][counter1]
174+
counter1 += 1
175+
176+
file.write("The universities that contain the capital name => \n") # PART 9 CAPITAL NAME IN UNIVERSITY NAME
177+
178+
for uni in TopUni["Country"]:
179+
if (selectedCountry == uni) and (capital in TopUni["Institution name"][counter2]):
180+
file.write("#" + str(number_counter) + " " + TopUni["Institution name"][counter2] + "\n")
181+
number_counter += 1
182+
counter2 += 1
183+
184+
185+
def __main__():
186+
country = input("input the country you want to look at: ")
187+
file1 = "TopUni.csv"
188+
file2 = "capitals.csv"
189+
getInformation(country, file1, file2)
190+
191+
192+
__main__()

0 commit comments

Comments
 (0)