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

Covid_Data_Visualization_Code

Covid data analysis

Uploaded by

brcg465
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views

Covid_Data_Visualization_Code

Covid data analysis

Uploaded by

brcg465
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 5

Python Data Visualization Code

import pandas as pd

import numpy as np

import matplotlib.pyplot as plt

def Fun():

print(":)")

print("#1. For checking the data.")

print("#2. Reading complete file without index.")

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. For Exit")

print("===============")

def Read_CSV(df):

print("The Data")

print(df)

def No_Index():

print("Reading the file without index")

df = pd.read_csv('Covid_data_kerala.csv', index_col=0)

print(df)

def line_plot(df):

if 'Districts' not in df.columns:

df['Districts'] =

['EKM','PTA','KTM','TSR','KKD','MPM','KLM','PKD','ALP','KNR','TVM','IDK','WYD','KGD']

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()

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")

def main_menu():

try:

df = pd.read_csv('Covid_data_kerala.csv')

except FileNotFoundError:

print("Error: File 'Covid_data_kerala.csv' not found.")

return

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:

Read_CSV(df)

elif YC == 2:

No_Index()

elif YC == 3:

line_plot(df)

elif YC == 4:
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!")

main_menu()

You might also like