Data Visualization on COVID - Python Code
Data Visualization on COVID - Python Code
import pandas as pd
import numpy as np
import [Link] as plt
# Generate random data for COVID-19 cases
def generate_random_data():
[Link](42) # For reproducibility
districts = ['EKM', 'PTA', 'KTM', 'TSR', 'KKD', 'MPM', 'KLM', 'PKD', 'ALP', 'KNR', 'TVM', 'IDK',
'WYD', 'KGD']
data = {
'Districts': districts,
'Confirmed': [Link](1000, 5000, len(districts)),
'Recovered': [Link](500, 4000, len(districts)),
'Deaths': [Link](10, 500, len(districts)),
'Active': [Link](100, 1000, len(districts)),
return [Link](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"]
[Link]("Districts")
YC = int(input("Enter the number representing your preferred line chart from the above choices:
"))
if YC == 1:
[Link]("Confirmed Cases")
[Link]("Districts Wise Confirmed Cases")
[Link](District, Confirmed, color='b')
[Link]()
elif YC == 2:
[Link]("Recovered Cases")
[Link]("Districts Wise Recovered Cases")
[Link](District, Recovered, color='g')
[Link]()
elif YC == 3:
[Link]("Death Cases")
[Link]("Districts Wise Death Cases")
[Link](District, Deaths, color='r')
[Link]()
Data Visualization on COVID - Python Code
elif YC == 4:
[Link]("Active Cases")
[Link]("Districts Wise Active Cases")
[Link](District, Active, color='c')
[Link]()
elif YC == 5:
[Link]("Number of cases")
[Link](District, Confirmed, color='b', label="Confirmed Cases")
[Link](District, Recovered, color='g', label="Recovered Cases")
[Link](District, Deaths, color='r', label="Death Cases")
[Link](District, Active, color='c', label="Active Cases")
[Link]()
[Link]()
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"]
[Link]("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:
[Link]("Confirmed Cases")
[Link]("Districts Wise Confirmed Cases")
[Link](District, Confirmed, color='b', width=0.5)
[Link]()
elif YC == 2:
[Link]("Recovered Cases")
[Link]("Districts Wise Recovered Cases")
[Link](District, Recovered, color='g', width=0.5)
[Link]()
elif YC == 3:
[Link]("Death Cases")
[Link]("Districts Wise Death Cases")
[Link](District, Deaths, color='r', width=0.5)
[Link]()
elif YC == 4:
[Link]("Active Cases")
[Link]("Districts Wise Active Cases")
[Link](District, Active, color='c', width=0.5)
[Link]()
elif YC == 5:
[Link](District, Confirmed, color='b', width=0.5, label="Confirmed Cases")
Data Visualization on COVID - Python Code
[Link](District, Recovered, color='g', width=0.5, label="Recovered Cases")
[Link](District, Deaths, color='r', width=0.5, label="Death Cases")
[Link](District, Active, color='c', width=0.5, label="Active Cases")
[Link]()
[Link]()
elif YC == 6:
D = [Link](len(District))
width = 0.25
[Link](D, Confirmed, width, color='b', label="Confirmed Cases")
[Link](D+0.25, Recovered, width, color='g', label="Recovered Cases")
[Link](D+0.50, Deaths, width, color='r', label="Death Cases")
[Link](D+0.75, Active, width, color='c', label="Active Cases")
[Link]()
[Link]()
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
[Link](District, Confirmed, color="b", label="Confirmed Cases")
[Link](District, Recovered, color="g", label="Recovered Cases")
[Link](District, Deaths, color="r", label="Death Cases")
[Link](District, Active, color="c", label="Active Cases")
[Link]("District")
[Link]("Complete Scatter Chart")
[Link]()
[Link]()
# 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()