Python NumPy Mini Projects: COVID Data Analysis
This project deals with COVID Data analysis. COVID has huge impact in the society. It affects the humans around the world. Let us analyse the data.
Code Implementation:
This
program creates an array of countries. There are three arrays for covid
confirmed, covid recovered and those who not survived(death).
- Calculate the details like total confirmed,total recovered and total death by adding the array elements.
- Recovery rate is calculated by the below formula,
- recovery_rate = (recovered / confirmed) * 100.
- Death rate is calculated by the formula given below,
- death_rate = (deaths / confirmed) * 100
- Maximum Cases are found using max() function.
- The active cases are also calculated by the formula given here.
- Active case = Confirmed - Recovered - Deaths
- Daily cases, Average cases, Maximum and minimum cases are printed using built-in functions.
- Finally, all calculations are displayed in the output screen.
Code:
import numpy as np
countries = np.array([
"India",
"USA",
"Russia",
"UK",
"Norway"
])
confirmed = np.array([55000000, 205000000, 27500000, 22000000,33000000])
recovered = np.array([44500000, 105000000, 36000000, 27500000,
20500000])
deaths = np.array([433000, 1040000, 600000, 490000, 530000])
#Total Confirmed Cases
total_confirmed = np.sum(confirmed)
print("Total Confirmed Cases:", total_confirmed)
#Total Recovered Cases
total_recovered = np.sum(recovered)
print("Total Recovered Cases:", total_recovered)
#Total Deaths
total_deaths = np.sum(deaths)
print("Total Deaths:", total_deaths)
#Recovery Rate
recovery_rate = (recovered / confirmed) * 100
for i in range(len(countries)):
print(countries[i],
":", round(recovery_rate[i], 2), "%")
#Death Rate
death_rate = (deaths / confirmed) * 100
for i in range(len(countries)):
print(countries[i],
":", round(death_rate[i], 2), "%")
#Country with Maximum Cases
max_index = np.argmax(confirmed)
print("Country with Maximum Cases:")
print(countries[max_index], confirmed[max_index])
#Active Cases
active_cases = confirmed - recovered - deaths
for i in range(len(countries)):
print(countries[i],
":", active_cases[i])
#Create Daily Cases Dataset
daily_cases = np.array([
1200, 1400, 1800, 2000,
2200,
2500, 2700, 3000, 3300,
3500
])
print("Daily Cases:")
print(daily_cases)
#Average Daily Cases
avg_cases = np.mean(daily_cases)
print("Average Cases:", avg_cases)
#Maximum and Minimum Cases
print("Maximum Cases:", np.max(daily_cases))
print("Minimum Cases:", np.min(daily_cases))
#Complete COVID Analysis Program
import numpy as np
countries = np.array(["India","USA","Brazil","Russia","UK"])
confirmed = np.array([45000000,105000000,37000000,22000000,25000000])
recovered = np.array([44400000,101000000,36000000,21500000,24500000])
deaths = np.array([533000,1140000,700000,390000,230000])
active = confirmed - recovered - deaths
print("===== COVID DATA ANALYSIS =====")
print("Total Confirmed :", np.sum(confirmed))
print("Total Recovered :", np.sum(recovered))
print("Total Deaths :", np.sum(deaths))
print("\nRecovery Rate (%)")
print(np.round((recovered/confirmed)*100,2))
print("\nDeath Rate (%)")
print(np.round((deaths/confirmed)*100,2))
print("\nActive Cases")
print(active)
max_country = countries[np.argmax(confirmed)]
print("\nHighest Cases Country:", max_country)
Output:
Total Confirmed Cases: 342500000
Total Recovered Cases: 233500000
Total Deaths: 3093000
India : 80.91 %
USA : 51.22 %
Russia : 130.91 %
UK : 125.0 %
Norway : 62.12 %
India : 0.79 %
USA : 0.51 %
Russia : 2.18 %
UK : 2.23 %
Norway : 1.61 %
Country with Maximum Cases:
USA 205000000
India : 10067000
USA : 98960000
Russia : -9100000
UK : -5990000
Norway : 11970000
Daily Cases:
[1200 1400 1800 2000 2200 2500 2700 3000 3300 3500]
Average Cases: 2360.0
Maximum Cases: 3500
Minimum Cases: 1200
===== COVID DATA ANALYSIS =====
Total Confirmed : 234000000
Total Recovered : 227400000
Total Deaths : 2993000
Recovery Rate (%)
[98.67 96.19 97.3
97.73 98. ]
Death Rate (%)
[1.18 1.09 1.89 1.77 0.92]
Active Cases
[ 67000 2860000 300000
110000 270000]
Highest Cases Country: USA
This is the way of analyzing the COVID data in NumPy using
Python. Hope, you found this code useful. Keep Coding!!!
Comments
Post a Comment