Data Visualization on COVID - Python Code
Data Visualization on COVID - Python Code
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
# Generate random data for COVID-19 cases
def generate_random_data():
np.random.seed(42) # For reproducibility
districts = ['EKM', 'PTA', 'KTM', 'TSR', 'KKD', 'MPM', 'KLM', 'PKD', 'ALP', 'KNR', 'TVM', 'IDK',
'WYD', 'KGD']
data = {
'Districts': districts,
'Confirmed': np.random.randint(1000, 5000, len(districts)),
'Recovered': np.random.randint(500, 4000, len(districts)),
'Deaths': np.random.randint(10, 500, len(districts)),
'Active': np.random.randint(100, 1000, len(districts)),
return pd.DataFrame(data)
# Display menu options
def Fun():
print(":)")
print("#1. Display the generated random data.")
Data Visualization on COVID - Python Code
print("===================")
print("Topic - Data Visualization")
print(" ")
print("#3. Line Chart")
print(" Press 1 to print the data for Confirmed cases as per Districts.")
print(" Press 2 to print the data for Recovered cases as per Districts.")
print(" Press 3 to print the data for Death cases as per Districts.")
print(" Press 4 to print the data for Active cases as per Districts.")
print(" Press 5 to print All data.")
print(" ")
print("#4. Bar Graph")
print(" Press 1 to print the data for Confirmed cases as per Districts.")
print(" Press 2 to print the data for Recovered cases as per Districts.")
print(" Press 3 to print the data for Death cases as per Districts.")
print(" Press 4 to print the data for Active cases as per Districts.")
print(" Press 5 to print the data in form of stack bar chart.")
print(" Press 6 to print the data in form of multi bar chart.")
print(" ")
print("#5. Scatter Chart")
print(" ")
print("#6. Exit")
print("===============")
# Line Chart Function
def line_plot(df):
Data Visualization on COVID - Python Code
District = df["Districts"]
Confirmed = df["Confirmed"]
Recovered = df["Recovered"]
Deaths = df["Deaths"]
Active = df["Active"]
plt.xlabel("Districts")
YC = int(input("Enter the number representing your preferred line chart from the above choices:
"))
if YC == 1:
plt.ylabel("Confirmed Cases")
plt.title("Districts Wise Confirmed Cases")
plt.plot(District, Confirmed, color='b')
plt.show()
elif YC == 2:
plt.ylabel("Recovered Cases")
plt.title("Districts Wise Recovered Cases")
plt.plot(District, Recovered, color='g')
plt.show()
elif YC == 3:
plt.ylabel("Death Cases")
plt.title("Districts Wise Death Cases")
plt.plot(District, Deaths, color='r')
plt.show()
Data Visualization on COVID - Python Code
elif YC == 4:
plt.ylabel("Active Cases")
plt.title("Districts Wise Active Cases")
plt.plot(District, Active, color='c')
plt.show()
elif YC == 5:
plt.ylabel("Number of cases")
plt.plot(District, Confirmed, color='b', label="Confirmed Cases")
plt.plot(District, Recovered, color='g', label="Recovered Cases")
plt.plot(District, Deaths, color='r', label="Death Cases")
plt.plot(District, Active, color='c', label="Active Cases")
plt.legend()
plt.show()
else:
print("Enter valid input")
# Bar Graph Function
def bar_plot(df):
District = df["Districts"]
Confirmed = df["Confirmed"]
Recovered = df["Recovered"]
Deaths = df["Deaths"]
Active = df["Active"]
plt.xlabel("Districts")
Data Visualization on COVID - Python Code
YC = int(input("Enter the number representing your preferred bar graph from the above
choices:"))
if YC == 1:
plt.ylabel("Confirmed Cases")
plt.title("Districts Wise Confirmed Cases")
plt.bar(District, Confirmed, color='b', width=0.5)
plt.show()
elif YC == 2:
plt.ylabel("Recovered Cases")
plt.title("Districts Wise Recovered Cases")
plt.bar(District, Recovered, color='g', width=0.5)
plt.show()
elif YC == 3:
plt.ylabel("Death Cases")
plt.title("Districts Wise Death Cases")
plt.bar(District, Deaths, color='r', width=0.5)
plt.show()
elif YC == 4:
plt.ylabel("Active Cases")
plt.title("Districts Wise Active Cases")
plt.bar(District, Active, color='c', width=0.5)
plt.show()
elif YC == 5:
plt.bar(District, Confirmed, color='b', width=0.5, label="Confirmed Cases")
Data Visualization on COVID - Python Code
plt.bar(District, Recovered, color='g', width=0.5, label="Recovered Cases")
plt.bar(District, Deaths, color='r', width=0.5, label="Death Cases")
plt.bar(District, Active, color='c', width=0.5, label="Active Cases")
plt.legend()
plt.show()
elif YC == 6:
D = np.arange(len(District))
width = 0.25
plt.bar(D, Confirmed, width, color='b', label="Confirmed Cases")
plt.bar(D+0.25, Recovered, width, color='g', label="Recovered Cases")
plt.bar(D+0.50, Deaths, width, color='r', label="Death Cases")
plt.bar(D+0.75, Active, width, color='c', label="Active Cases")
plt.legend()
plt.show()
else:
print("Enter valid input")
# Scatter Chart Function
def scatter_chart(df):
District = df["Districts"]
Confirmed = df["Confirmed"]
Recovered = df["Recovered"]
Deaths = df["Deaths"]
Active = df["Active"]
Data Visualization on COVID - Python Code
plt.scatter(District, Confirmed, color="b", label="Confirmed Cases")
plt.scatter(District, Recovered, color="g", label="Recovered Cases")
plt.scatter(District, Deaths, color="r", label="Death Cases")
plt.scatter(District, Active, color="c", label="Active Cases")
plt.xlabel("District")
plt.title("Complete Scatter Chart")
plt.legend()
plt.show()
# Main Menu Function
def main_menu():
df = generate_random_data()
Fun()
while True:
try:
YC = int(input("Enter Your Choice: "))
except ValueError:
print("Invalid input! Please enter a number between 1 and 6.")
continue
if YC == 1:
print(df)
elif YC == 3:
line_plot(df)
elif YC == 4:
Data Visualization on COVID - Python Code
bar_plot(df)
elif YC == 5:
scatter_chart(df)
elif YC == 6:
print("Thank you for using the tool!")
break
else:
print("Enter a valid input!")
# Run the program
main_menu()