0% found this document useful (0 votes)
16 views

CSV File

Uploaded by

mananjaju56
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
16 views

CSV File

Uploaded by

mananjaju56
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 11

GDP Analysis Project - Queries and Solutions

This document contains 9 queries and their solutions based on GDP analysis for the

years 2020, 2021, and 2022. The queries include operations such as finding maximum

and minimum GDP, growth rates, averages, and more, implemented manually without

importing external CSV libraries.


Queries and Solutions

1. Find the country with the highest GDP in 2022.

Code:

max_gdp_2022 = max(data, key=lambda x: float(x[3]))

print(f"Country with highest GDP in 2022: {max_gdp_2022[0]} -

{max_gdp_2022[3]} Trillion USD")

Answer:

Country with highest GDP in 2022: USA - 25.5

Trillion USD

2. Find the country with the lowest GDP in 2020.

Code:

min_gdp_2020 = min(data, key=lambda x: float(x[1]))

print(f"Country with lowest GDP in 2020: {min_gdp_2020[0]} -

{min_gdp_2020[1]} Trillion USD")

Answer:

Country with lowest GDP in 2020: India - 3.3

Trillion USD

3. Calculate the average GDP for 2021.

Code:

avg_gdp_2021 = sum(float(row[2]) for row in data) /


len(data) print(f"Average GDP in 2021:

{avg_gdp_2021:.2f} Trillion USD")

Answer:

Average GDP in 2021: 10.58

Trillion USD

4. Find the total GDP of all countries for 2022.

Code:

total_gdp_2022 = sum(float(row[3]) for row in data)

print(f"Total GDP in 2022: {total_gdp_2022:.2f}

Trillion USD")

Answer:

Total GDP in 2022: 55.30 Trillion USD

5. Find the country with the highest GDP growth rate from 2020 to 2021.

Code:

growth_2020_2021 = [(row[0], (float(row[2]) - float(row[1])) / float(row[1]) * 100) for

row in data] max_growth = max(growth_2020_2021, key=lambda x: x[1])

print(f"Country with highest GDP growth rate (2020-2021): {max_growth[0]} -

{max_growth[1]:.2f}%")

Answer:

Country with highest GDP growth rate (2020-2021): China

- 26.06%
6. Find all countries with GDP greater than 5 trillion USD in 2022.

Code:

countries_above_5_trillion = [row[0] for row in data if float(row[3]) > 5.0]

print(f"Countries with GDP greater than 5 Trillion USD in 2022: {',

'.join(countries_above_5_trillion)}")

Answer:

Countries with GDP greater than 5 Trillion USD in 2022: USA,

China, Germany

7. Rank all countries based on their GDP in 2022.

Code:

ranked_data = sorted(data, key=lambda x: float(x[3]),

reverse=True) print("Rank of countries by GDP in 2022:")

for rank, row in enumerate(ranked_data, 1):

print(f"{rank}. {row[0]} - {row[3]} Trillion USD")

Answer:

1. USA - 25.5 Trillion USD

2. China - 19.5 Trillion USD

3. Germany - 5.5 Trillion USD

4. Japan - 4.7 Trillion USD

5. India - 4.1 Trillion USD

8. Calculate the GDP growth rate for each country from 2021 to 2022.
Code:

growth_2021_2022 = [(row[0], (float(row[3]) - float(row[2])) / float(row[2]) *

100) for row in data] for country, growth in growth_2021_2022:

print(f"{country}: {growth:.2f}%")

Answer:

USA: 10.87%

China: 8.94%

Japan: -2.08%

Germany:

0.00%

India: 17.14%

9. Find the total GDP of countries with GDP below 5 trillion USD in 2022.

Code:
total_below_5 = sum(float(row[3]) for row in data if float(row[3]) < 5.
print(f"Total GDP of countries with GDP below 5 Trillion USD in 2022:
{total_below_5:.2f} Trillion USD")
Answer:

Total GDP of countries with GDP below 5 Trillion USD in 2022: 8.80

Trillion USD

You might also like