Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
241 changes: 241 additions & 0 deletions Lab14-20sw015.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,241 @@
{
"nbformat": 4,
"nbformat_minor": 0,
"metadata": {
"colab": {
"provenance": [],
"authorship_tag": "ABX9TyMY0BfEf2aELbd4J8PVirnO",
"include_colab_link": true
},
"kernelspec": {
"name": "python3",
"display_name": "Python 3"
},
"language_info": {
"name": "python"
}
},
"cells": [
{
"cell_type": "markdown",
"metadata": {
"id": "view-in-github",
"colab_type": "text"
},
"source": [
"<a href=\"https://colab.research.google.com/github/nayab-nisar/DS-A_Tasks/blob/main/Lab14.ipynb\" target=\"_parent\"><img src=\"https://colab.research.google.com/assets/colab-badge.svg\" alt=\"Open In Colab\"/></a>"
]
},
{
"cell_type": "code",
"execution_count": 3,
"metadata": {
"id": "vBZKRMrFU4gT"
},
"outputs": [],
"source": [
"import pandas as pd\n",
"\n",
"# Create a DataFrame from the provided data\n",
"\n",
"df = pd.read_csv('/WorldCups.csv');\n"
]
},
{
"cell_type": "code",
"source": [
"\n",
"# Convert 'Goals' to numeric (remove commas if any)\n",
"df['Goals'] = df['Goals'].replace(',', '', regex=True).astype(int)"
],
"metadata": {
"id": "SQGaaCjEa56Z"
},
"execution_count": null,
"outputs": []
},
{
"cell_type": "code",
"source": [
"\n",
"# Which team won the most World Cups, and how many wins was that?\n",
"most_wins_team = df['Winner'].value_counts().idxmax()\n",
"most_wins_count = df['Winner'].value_counts().max()\n",
"print(f'Team with the most World Cup wins: {most_wins_team}, Wins: {most_wins_count}')\n"
],
"metadata": {
"colab": {
"base_uri": "https://localhost:8080/"
},
"id": "L5dfYQqYXfwR",
"outputId": "c1be125a-c758-4a7d-96ae-2ed38c994140"
},
"execution_count": 5,
"outputs": [
{
"output_type": "stream",
"name": "stdout",
"text": [
"Team with the most World Cup wins: Brazil, Wins: 5\n"
]
}
]
},
{
"cell_type": "code",
"source": [
"#Which team won the most World Cups, and how many wins was that?\n",
"most_wins_team = df['Winner'].value_counts().idxmax()\n",
"most_wins_count = df['Winner'].value_counts().max()\n",
"print(f'Team with the most World Cup wins: {most_wins_team}, Wins: {most_wins_count}')\n"
],
"metadata": {
"colab": {
"base_uri": "https://localhost:8080/"
},
"id": "Iod8vI1EbBl9",
"outputId": "3ba3c139-9eb7-410b-ba04-8a09e93520a2"
},
"execution_count": 19,
"outputs": [
{
"output_type": "stream",
"name": "stdout",
"text": [
"Team with the most World Cup wins: Brazil, Wins: 5\n"
]
}
]
},
{
"cell_type": "code",
"source": [
"\n",
"# Which Finals or Semi-final games were decided by penalties?\n",
"penalty_games = df[(df['Goals'] % 2 != 0) & ((df['Round'] == 'Final') | (df['Round'] == 'Semi-finals'))]\n",
"print('Finals or Semi-final games decided by penalties:')\n",
"print(penalty_games)\n"
],
"metadata": {
"id": "5fJYu3jdbEcF"
},
"execution_count": null,
"outputs": []
},
{
"cell_type": "code",
"source": [
"\n",
"# Which years had the highest and lowest attendance to the World Cup games?\n",
"highest_attendance_year = df[df['Goals'] == df['Goals'].max()]['Year'].values[0]\n",
"lowest_attendance_year = df[df['Goals'] == df['Goals'].min()]['Year'].values[0]\n",
"print(f'Highest attendance year: {highest_attendance_year}')\n",
"print(f'Lowest attendance year: {lowest_attendance_year}')\n"
],
"metadata": {
"id": "mlKQ25IKbG-A"
},
"execution_count": null,
"outputs": []
},
{
"cell_type": "code",
"source": [
"\n",
"# What's the average number of goals scored per World Cup?\n",
"average_goals_per_world_cup = df['Goals'].mean()\n",
"print(f'Average goals scored per World Cup: {average_goals_per_world_cup:.2f}')\n"
],
"metadata": {
"id": "A6vf_hKvbIsW"
},
"execution_count": null,
"outputs": []
},
{
"cell_type": "code",
"source": [
"\n",
"# Which team won the most World Cups, and how many wins was that?\n",
"most_wins_team = df['Winner'].value_counts().idxmax()\n",
"most_wins_count = df['Winner'].value_counts().max()\n",
"print(f'Team with the most World Cup wins: {most_wins_team}, Wins: {most_wins_count}')\n",
"\n"
],
"metadata": {
"colab": {
"base_uri": "https://localhost:8080/"
},
"id": "nsXXNEcKahw6",
"outputId": "29deb728-0c12-48ac-b281-d49c60d5d7fa"
},
"execution_count": 16,
"outputs": [
{
"output_type": "stream",
"name": "stdout",
"text": [
"Team with the most World Cup wins: Brazil, Wins: 5\n"
]
}
]
},
{
"cell_type": "code",
"source": [
"\n",
"# How many countries qualified for the World Cup in 1930 compared to 2014?\n",
"countries_1930 = 4 # Given in the dataset\n",
"countries_2014 = 32 # Given in the dataset\n",
"print(f'Countries that qualified in 1930: {countries_1930}')\n",
"print(f'Countries that qualified in 2014: {countries_2014}')\n"
],
"metadata": {
"colab": {
"base_uri": "https://localhost:8080/"
},
"id": "uIUdwv45YUvY",
"outputId": "83eaaec7-4034-428f-82ec-ac2b17d68b9c"
},
"execution_count": 9,
"outputs": [
{
"output_type": "stream",
"name": "stdout",
"text": [
"Countries that qualified in 1930: 4\n",
"Countries that qualified in 2014: 32\n"
]
}
]
},
{
"cell_type": "code",
"source": [
"\n",
"# Does history show more home-team wins or away-team wins?\n",
"# Assuming home-team as the team mentioned first in each row\n",
"home_wins = df[df['Year'] >= 1930]['Winner'].value_counts().sum()\n",
"away_wins = len(df) - home_wins\n",
"print(f'Home-team wins: {home_wins}, Away-team wins: {away_wins}')\n"
],
"metadata": {
"colab": {
"base_uri": "https://localhost:8080/"
},
"id": "wLJCgkV0YXyJ",
"outputId": "8953f348-338f-4f31-84a8-e52b1b835bd1"
},
"execution_count": 10,
"outputs": [
{
"output_type": "stream",
"name": "stdout",
"text": [
"Home-team wins: 20, Away-team wins: 0\n"
]
}
]
}
]
}
Loading