ieeextreme


Analyzing Data with Python: Counting how many times each value in a CSV occurs

Data analysis is an essential aspect of many fields, from business and research to sports and education. Python, with its versatile libraries, is a popular choice for data analysis tasks. In this blog post, we’ll explore a Python script that reads data from a CSV file and counts the occurrences of each value in 3 columns. The script can be a valuable tool for gaining insights into educational information datasets.

#!/bin/python

import csv

# Create empty dictionaries
d_university = dict()
d_country = dict()
d_region = dict()

with open('XtremeScores.csv') as f:
    reader = csv.reader(f, delimiter=',', quoting=csv.QUOTE_NONE)
    # Loop through each line of the file
    for line in reader:
        word = line[6]
        # Check if the word is already in dictionary
        if word in d_region:
            # Increment count of word by 1
            d_region[word] = d_region[word] + 1
        else:
            # Add the word to dictionary with count 1
            d_region[word] = 1

        word = line[5]
        # Check if the word is already in dictionary
        if word in d_country:
            # Increment count of word by 1
            d_country[word] = d_country[word] + 1
        else:
            # Add the word to dictionary with count 1
            d_country[word] = 1

        word = line[4]
        # Check if the word is already in dictionary
        if word in d_university:
            # Increment count of word by 1
            d_university[word] = d_university[word] + 1
        else:
            # Add the word to dictionary with count 1
            d_university[word] = 1

sorted_university = sorted(d_university.items(), key=lambda x:x[1], reverse=True)
print(sorted_university[:10])
sorted_country = sorted(d_country.items(), key=lambda x:x[1], reverse=True)
print(sorted_country[:10])
sorted_region = sorted(d_region.items(), key=lambda x:x[1], reverse=True)
print(sorted_region[:10])

Let’s break down the code step by step:

#!/bin/python

import csv

The script starts by importing the csv module, which is essential for handling comma-separated value (CSV) files.

# Create empty dictionaries
d_university = dict()
d_country = dict()
d_region = dict()

Three empty dictionaries, d_university, d_country, and d_region, are created. These dictionaries will be used to store the counts of universities, countries, and regions, respectively.

with open('XtremeScores.csv') as f:
    reader = csv.reader(f, delimiter=',', quoting=csv.QUOTE_NONE)

The script opens a CSV file named ‘XtremeScores.csv’ using a with statement. The csv.reader object is used to read the contents of the file. We specify that the delimiter is a comma (,), and we don’t want to perform any special quoting.

    # Loop through each line of the file
    for line in reader:

A for loop iterates through each line in the CSV file. The variable line contains the data for each row in the file.

        word = line[6]

The code extracts the word at index 6 (zero-based index) from the current line. In this context, it typically represents a region.

        # Check if the word is already in the dictionary
        if word in d_region:
            # Increment count of word by 1
            d_region[word] = d_region[word] + 1
        else:
            # Add the word to the dictionary with count 1
            d_region[word] = 1

The code checks if the extracted word (representing a region) is already present in the d_region dictionary. If it is, it increments the count by 1. If not, it adds the word to the dictionary with a count of 1. This process counts the occurrences of each region in the dataset.

The code repeats the same process for words representing countries (at index 5) and universities (at index 4), using the d_country and d_university dictionaries, respectively.

sorted_university = sorted(d_university.items(), key=lambda x:x[1], reverse=True)
print(sorted_university[:10])

After counting the universities, the code sorts them in descending order of frequency and prints the top 10 universities based on their occurrence.

sorted_country = sorted(d_country.items(), key=lambda x:x[1], reverse=True)
print(sorted_country[:10])

Similarly, it does the same for countries and prints the top 10 countries.

sorted_region = sorted(d_region.items(), key=lambda x:x[1], reverse=True)
print(sorted_region[:10])

Finally, it sorts and prints the top 10 regions based on their occurrence.

In summary, this Python script provides a simple but effective way to analyze data in a CSV file, specifically counting universities, countries, and regions. It leverages dictionaries to maintain counts and uses the csv module for reading data from the file. This can be a useful starting point for more advanced data analysis tasks and visualization in Python.


Join IEEEXtreme Coding Competition

Are you a university or college student looking for a challenge? Look no further than the IEEEXtreme international programming competition!

IEEEXtreme is a 24-hour, online, global coding competition that brings together students from all over the world to test their skills and knowledge against their peers. This competition is organized by the IEEE, the world’s largest technical professional organization for the advancement of technology.

Participating in IEEEXtreme provides a unique opportunity for students to showcase their skills and gain recognition in the global tech community. Not only that, but it also allows students to connect with their peers from around the world and learn from each other.

But the benefits of IEEEXtreme don’t stop there. Participating in the competition can also help students develop essential skills employers highly value. These skills include problem-solving, critical thinking, and the ability to work under pressure.

Another great thing about IEEEXtreme is that it’s open to students of all skill levels. Whether a beginner or an experienced coder, you can participate and challenge yourself to improve. And with a wide variety of categories to choose from, there’s something for everyone.

So if you’re a university or college student looking for a challenge and an opportunity to showcase your skills and connect with others in the tech community, then IEEEXtreme is the perfect competition for you. Sign up today and see how far you can go!

In summary, IEEEXtreme is a 24-hour, online, global coding competition which is organized by IEEE, it gives the opportunity for university and college students to showcase their skills, connect with peers from around the world, develop important skills that are highly valued by employers, and it’s open to students of all skill levels. It is a perfect competition for anyone looking for a challenge.


IEEEXtreme 15.0 Call for Judges / Problem Authors

Are you fascinated by programming? We, the IEEEXtreme 15.0 Executive Committee, are opening the registrations for a select few judges and problem authors.

IEEEXtreme is a global challenge in which teams of IEEE student members compete in a 24-hour time span against each other to solve a set of programming problems authored by industry professionals and coding experts like yourself. Over the 15 years since it began, the competition has attracted over 70,000 competitors from over 2,500 schools in 90 countries around the world.

This is an opportunity where you can not only develop the coding challenges but also you can evaluate them while having the opportunity to associate with some of the top experts in the field. The judging staff of IEEEXtreme are all volunteers who strive to make the contest a fun and exciting experience for all.

Judges responsibilities may include one or more of the following:

Develop at least 1 original and innovative problem. You may see examples of the format of the IEEEXtreme problems here: https://csacademy.com/ieeextreme-practice/
Review and evaluate the problems proposed by another judge and provide feedback;
Provide independent solutions to other proposed problems using any of the competition programming languages;
Be online during the day of the competition for 1-2 hours based on their availability in order to address the contestants’ questions related to the authored challenge.

While not everyone who submits a nomination will be selected, we will carefully review all nominations and thank you in advance for your time to express your interest! We look forward to welcoming you aboard to the IEEEXtreme community!

Please apply using this form on or before 2021/09/19.

More delineations can be acquired from: [email protected]


IEEEXtreme: What Did The Penalty Bracket Mean?

The penalty (per challenge), is the time in minutes between the initial release of a challenge and the time at which a team submitted their best answer to that challenge.

For example, the challenge named “Crafting Wooden Tables” was released on the 5th hour of the 14.0 IEEEXtreme competition (05:00 UTC +0).

If a team had their best solution to this challenge submitted at 19:59 (UTC +0), which gives us almost a 15 hour delay, then the penalty for that challenge would be 899 point (14 hours * 60 minutes + 59 minutes = 899 minutes since the release of the challenge.)

Each teams’ total penalty is the sum of all individual penalties.