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

Project Code Samples

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

Project Code Samples

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

Code Sample 1 – User interactive choices

import numpy as np # linear algebra


import pandas as pd # data processing, CSV file I/O (e.g. pd.read_csv)

#importing the csv file using read_csv function of pandas module


import pandas as pa

# Showing the literacy rate of India 1951 - 2011 data post conversion into the
dataframe
print("The Vaccine Status of all the States of India in 2021 \n")
Vdf=pa.read_csv('../input/vaccineindia2021/Vaacine.csv')

# User-Interactive Display of Extracted Information


print("Choose and Enter A Number between 1 and 6 To See \n ")
print("The Total Vaccine Administered Dose Wise and State Wise --1 \n ")
print("The Total Vaccine Administered Dose Wise and Gender Wise --2 \n")
print("The Total of Each Type of Vaccine and State Wise --3 \n")
print("The Total of Individuals Vaccinated State Wise --4 \n")
print("The Average of the Doses Adminstered, Each Type of Vaccine, Genders
Vaccinated --5 \n")
print("The Highest and the Lowest Vaccinated State in India --6 \n")

# Now user will input his/her chosen number

choice1=input("Enter the number of your choice ( Between 1 to 6 ) :- ")


if choice1 == '1':
print(" --------------------------- The Total Vaccine Administered Dose Wise and State
Wise ---------------------- \n ")
a=Vdf.groupby(['State'])['First Dose Administered'].sum()
b=Vdf.groupby(['State'])['Second Dose Administered'].sum()
c=Vdf.groupby(['State'])['Total Doses Administered'].sum()
print( "\n State Wise - Total First Dose Administered \n ", a)
print( "\n State Wise - Total Second Dose Administered \n ", b)
print( "\n State Wise - Total Third Dose Administered \n ", c)
choice2=input("Do you wish to see the total of doses administered in India (Y/N) --
")
if choice2 == 'Y' or 'y':
tot_first_doses=Vdf['First Dose Administered'].sum()
tot_second_doses=Vdf['Second Dose Administered'].sum()
tot_doses=Vdf['Total Doses Administered'].sum()
print( " \n ------ The total First Dose Administered in India = ", tot_first_doses)
print( " \n ------ The total Second Dose Administered in India = ",
tot_second_doses)
print( " \n ------ The Total Doses Administered in India = ", tot_doses)

elif choice1 == '2':


print(" -------------------------- The Total Vaccine Administered Gender Wise and State
Wise ---------------------- \n ")
d=Vdf.groupby(['State'])['Male (Doses Administered)'].sum()
e=Vdf.groupby(['State'])['Female (Doses Administered)'].sum()
f=Vdf.groupby(['State'])['Transgender (Doses Administered)'].sum()
print( "\n State Wise - Total Males Vaccinated \n ", d)
print( "\n State Wise - Total Females Vaccinated \n ", e)
print( "\n State Wise - Total Transgenders Vaccinated \n ", f)
choice2=input("Do you wish to see the total of doses administered gender wise in
India (Y/N) -- ")
if choice2 == 'Y' or 'y':
tot_male=Vdf['Male (Doses Administered)'].sum()
tot_female=Vdf['Female (Doses Administered)'].sum()
tot_transgender=Vdf['Transgender (Doses Administered)'].sum()
print( " \n ------ The total Male Administered with both the doses in India = ",
tot_male)
print( " \n ------ The total Female Administered with both the doses in India = ",
tot_female)
print( " \n ------ The total Transgenders Administered with both the doses in
India = ", tot_transgender)
print( " \n ------ The Total Population Administered with both the doses in India
= ", tot_doses)

elif choice1 == '3':


print(" -------------------------- The Total of Each Type of Vaccine and State Wise
---------------------------- \n ")
j=Vdf.groupby(['State'])[' Covaxin (Doses Administered)'].sum()
k=Vdf.groupby(['State'])['CoviShield (Doses Administered)'].sum()
l=Vdf.groupby(['State'])['Sputnik V (Doses Administered)'].sum()
print(" \n ------ State Wise - Total Covaxin Vaccinated are \n ", j)
print(" \n ------ State Wise - Total CoviShield Vaccinated are \n ", k)
print(" \n ------ State Wise - Total Sputnik Vaccinated are \n ", l)
m=Vdf[' Covaxin (Doses Administered)'].sum()
n=Vdf['CoviShield (Doses Administered)'].sum()
o=Vdf['Sputnik V (Doses Administered)'].sum()
print(" \n ------ Total Covaxin Doses Administered in India are = ", m)
print(" \n ------ Total CoviShield Doses Administered in India are = ", n)
print(" \n ------ Total Sputnik Doses Administered in India are = ", o)

elif choice1 == '4':


print(" -------------------------- The Total of Individuals Vaccinated State Wise
------------------------ \n ")
g=Vdf.groupby(['State'])['Total Individuals Vaccinated'].sum()
print( "\n - The Total of Individuals Vaccinated State Wise \n ", g)

elif choice1 == '5':


print(" --------- The Average of the Each Doses Adminstered, Each Type of Vaccine,
Genders Vaccinated --------- \n")
h=Vdf[['First Dose Administered','Second Dose Administered','Total Doses
Administered']].mean()
print("\n The Average of the Each Doses Adminstered = \n ", h)
i=Vdf[[' Covaxin (Doses Administered)','CoviShield (Doses Administered)','Sputnik
V (Doses Administered)']].mean()
print("\n The Average of the Each Type of Vaccines Adminstered = \n ", i)
j=Vdf['Total Individuals Vaccinated'].mean()
print("\n The Average of the Total Individuals Vaccineted in India = \n ", j)

elif choice1== '6':


print("\n The Highest and the Lowest Vaccinated State in India \n")
maxi=Vdf['Total Individuals Vaccinated'].max()
mini=Vdf['Total Individuals Vaccinated'].min()
print( "\n The State with the Highest Vaccinated Population is = ")
a=Vdf[Vdf['Total Individuals Vaccinated']==maxi].index.values
print(Vdf.iloc[a]['State'])
print( "\n The State with the Least Vaccinated Population is = ")
b=Vdf[Vdf['Total Individuals Vaccinated']==mini].index.values
print(Vdf.iloc[b]['State'])

print("Let us see some Graphical Comparison of \n 1. Gender Wise Total and Average
Vaccines Adminstered. \n")
print("2. Doses Wise Total and Average Vaccines Administered \n")
print("3. Average and Total of Each Type of Vaccines Administered \n")
print("4. Average and Total of Each State's Population Vaccines Administered \n")

# importing matplotlib packages


import matplotlib.pyplot as plt

print("Line Graph for Gender Wise Comparison of Total Vaccines Adminstered. \n")
a=Vdf['Male (Doses Administered)'].sum()
b=Vdf['Female (Doses Administered)'].sum()
c=Vdf['Transgender (Doses Administered)'].sum()
y=['Male (Doses Administered)','Female (Doses Administered)','Transgender (Doses
Administered)']
plt.plot(y,[a,b,c])
plt.title('Comparison of Total Doses Administered Gender Wise ', color='red')
plt.xlabel("Gender", color='red', fontsize=11)
plt.ylabel ("Total Doses", color='Green', fontsize=11)
plt.show()

print("\n Bar Graph for Doses Wise Total Vaccines Administered \n")

tot_male=Vdf['First Dose Administered'].sum()


tot_female=Vdf['Second Dose Administered'].sum()
tot_transgender=Vdf['Total Doses Administered'].sum()
plt.bar(['First','Second', 'Third'],[tot_male,tot_female,tot_transgender])
plt.title('Doses Wise Total Vaccines')
plt.xlabel("Doses", color='red', fontsize=11)
plt.ylabel ("Total Doses", color='Green', fontsize=11)
plt.show()

# Input data files are available in the read-only "../input/" directory


# For example, running this (by clicking run or pressing Shift+Enter) will list all files
under the input directory

import os
for dirname, _, filenames in os.walk('/kaggle/input'):
for filename in filenames:
print(os.path.join(dirname, filename))

# You can write up to 20GB to the current directory (/kaggle/working/) that gets
preserved as output when you create a version using "Save & Run All"
# You can also write temporary files to /kaggle/temp/, but they won't be saved
outside of the current session

Code 2 Sample ( With widgets instead of choices)


import numpy as np # for linear algebra
import pandas as pd # for data processing and CSV file I/O
import matplotlib.pyplot as plt
import ipywidgets as widgets
from IPython.display import display

# Load data
print("The Vaccine Status of all the States of India in 2021 \n")
Vdf = pd.read_csv('/kaggle/input/vaccineindia2021/Vaacine.csv') # Adjusted path to the
uploaded file

# User-Interactive Display of Extracted Information


print("Choose a number between 1 and 6 to see the data as follows:")
print("1 - The Total Vaccine Administered Dose Wise and State Wise")
print("2 - The Total Vaccine Administered Dose Wise and Gender Wise")
print("3 - The Total of Each Type of Vaccine and State Wise")
print("4 - The Total of Individuals Vaccinated State Wise")
print("5 - The Average of Doses Administered, Each Type of Vaccine, Genders Vaccinated")
print("6 - The Highest and the Lowest Vaccinated State in India")

# Dropdown widget for choice selection


choice_widget = widgets.Dropdown(
options=[('Total Vaccine Administered Dose Wise and State Wise', '1'),
('Total Vaccine Administered Dose Wise and Gender Wise', '2'),
('Each Type of Vaccine and State Wise', '3'),
('Individuals Vaccinated State Wise', '4'),
('Average Doses Administered and Genders Vaccinated', '5'),
('Highest and Lowest Vaccinated State in India', '6')],
description='Choice:',
)
display(choice_widget)

def show_data(choice):
if choice == '1':
print("Total Vaccine Administered Dose Wise and State Wise")
a = Vdf.groupby('State')['First Dose Administered'].sum()
b = Vdf.groupby('State')['Second Dose Administered'].sum()
c = Vdf.groupby('State')['Total Doses Administered'].sum()
print("\nState Wise - Total First Dose Administered\n", a)
print("\nState Wise - Total Second Dose Administered\n", b)
print("\nState Wise - Total Third Dose Administered\n", c)
tot_first_doses = Vdf['First Dose Administered'].sum()
tot_second_doses = Vdf['Second Dose Administered'].sum()
tot_doses = Vdf['Total Doses Administered'].sum()
print("\nTotal First Dose Administered in India =", tot_first_doses)
print("Total Second Dose Administered in India =", tot_second_doses)
print("Total Doses Administered in India =", tot_doses)

elif choice == '2':


print("Total Vaccine Administered Gender Wise and State Wise")
d = Vdf.groupby('State')['Male (Doses Administered)'].sum()
e = Vdf.groupby('State')['Female (Doses Administered)'].sum()
f = Vdf.groupby('State')['Transgender (Doses Administered)'].sum()
print("\nState Wise - Total Males Vaccinated\n", d)
print("\nState Wise - Total Females Vaccinated\n", e)
print("\nState Wise - Total Transgenders Vaccinated\n", f)

elif choice == '3':


print("Total of Each Type of Vaccine and State Wise")
j = Vdf.groupby('State')['Covaxin (Doses Administered)'].sum()
k = Vdf.groupby('State')['CoviShield (Doses Administered)'].sum()
l = Vdf.groupby('State')['Sputnik V (Doses Administered)'].sum()
print("\nState Wise - Total Covaxin Vaccinated\n", j)
print("\nState Wise - Total CoviShield Vaccinated\n", k)
print("\nState Wise - Total Sputnik Vaccinated\n", l)

elif choice == '4':


print("Total of Individuals Vaccinated State Wise")
g = Vdf.groupby('State')['Total Individuals Vaccinated'].sum()
print("\nTotal of Individuals Vaccinated State Wise\n", g)

elif choice == '5':


print("Average of Each Doses Administered, Each Type of Vaccine, Genders
Vaccinated")
h = Vdf[['First Dose Administered', 'Second Dose Administered', 'Total Doses
Administered']].mean()
print("\nAverage of Each Doses Administered\n", h)
i = Vdf[['Covaxin (Doses Administered)', 'CoviShield (Doses Administered)', 'Sputnik V
(Doses Administered)']].mean()
print("\nAverage of Each Type of Vaccines Administered\n", i)

elif choice == '6':


print("The Highest and the Lowest Vaccinated State in India")
max_vaccinated = Vdf['Total Individuals Vaccinated'].max()
min_vaccinated = Vdf['Total Individuals Vaccinated'].min()
highest_state = Vdf[Vdf['Total Individuals Vaccinated'] == max_vaccinated]['State']
lowest_state = Vdf[Vdf['Total Individuals Vaccinated'] == min_vaccinated]['State']
print("State with Highest Vaccinated Population:", highest_state.values[0])
print("State with Least Vaccinated Population:", lowest_state.values[0])

# Display results based on dropdown choice


choice_widget.observe(lambda change: show_data(change.new), names='value')

Code Sample 3 – Menu based with Exit Option


def display_menu():
print("Choose a number between 1 and 6 to see:")
print("1. Total Vaccine Administered Dose Wise and State Wise")
print("2. Total Vaccine Administered Gender Wise and State Wise")
print("3. Total of Each Type of Vaccine and State Wise")
print("4. Total of Individuals Vaccinated State Wise")
print("5. Average of Doses Administered, Each Type of Vaccine, Genders Vaccinated")
print("6. Highest and Lowest Vaccinated State in India")
print("Enter '0' to exit.")

def execute_choice(choice):
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt

# Load the dataset


Vdf = pd.read_csv('/kaggle/input/vaccineindia2021/Vaacine.csv')

def display_menu():
print("Choose a number between 1 and 6 to see:")
print("1. Total Vaccine Administered Dose Wise and State Wise")
print("2. Total Vaccine Administered Gender Wise and State Wise")
print("3. Total of Each Type of Vaccine and State Wise")
print("4. Total of Individuals Vaccinated State Wise")
print("5. Average of Doses Administered, Each Type of Vaccine, Genders Vaccinated")
print("6. Highest and Lowest Vaccinated State in India")
print("Enter '0' to exit.")

def execute_choice(choice):
if choice == '1':
print("Total Vaccine Administered Dose Wise and State Wise")
a = Vdf.groupby('State')['First Dose Administered'].sum()
b = Vdf.groupby('State')['Second Dose Administered'].sum()
c = Vdf.groupby('State')['Total Doses Administered'].sum()
print("\nState Wise - Total First Dose Administered\n", a)
print("\nState Wise - Total Second Dose Administered\n", b)
print("\nState Wise - Total Third Dose Administered\n", c)
tot_first_doses = Vdf['First Dose Administered'].sum()
tot_second_doses = Vdf['Second Dose Administered'].sum()
tot_doses = Vdf['Total Doses Administered'].sum()
print("\nTotal First Dose Administered in India =", tot_first_doses)
print("Total Second Dose Administered in India =", tot_second_doses)
print("Total Doses Administered in India =", tot_doses)

elif choice == '2':


print("Total Vaccine Administered Gender Wise and State Wise")
d = Vdf.groupby('State')['Male (Doses Administered)'].sum()
e = Vdf.groupby('State')['Female (Doses Administered)'].sum()
f = Vdf.groupby('State')['Transgender (Doses Administered)'].sum()
print("\nState Wise - Total Males Vaccinated\n", d)
print("\nState Wise - Total Females Vaccinated\n", e)
print("\nState Wise - Total Transgenders Vaccinated\n", f)

elif choice == '3':


print("Total of Each Type of Vaccine and State Wise")
j = Vdf.groupby('State')['Covaxin (Doses Administered)'].sum()
k = Vdf.groupby('State')['CoviShield (Doses Administered)'].sum()
l = Vdf.groupby('State')['Sputnik V (Doses Administered)'].sum()
print("\nState Wise - Total Covaxin Vaccinated\n", j)
print("\nState Wise - Total CoviShield Vaccinated\n", k)
print("\nState Wise - Total Sputnik Vaccinated\n", l)

elif choice == '4':


print("Total of Individuals Vaccinated State Wise")
g = Vdf.groupby('State')['Total Individuals Vaccinated'].sum()
print("\nTotal of Individuals Vaccinated State Wise\n", g)

elif choice == '5':


print("Average of Each Doses Administered, Each Type of Vaccine, Genders
Vaccinated")
h = Vdf[['First Dose Administered', 'Second Dose Administered', 'Total Doses
Administered']].mean()
print("\nAverage of Each Doses Administered\n", h)
i = Vdf[['Covaxin (Doses Administered)', 'CoviShield (Doses Administered)', 'Sputnik V
(Doses Administered)']].mean()
print("\nAverage of Each Type of Vaccines Administered\n", i)

elif choice == '6':


print("The Highest and the Lowest Vaccinated State in India")
max_vaccinated = Vdf['Total Individuals Vaccinated'].max()
min_vaccinated = Vdf['Total Individuals Vaccinated'].min()
highest_state = Vdf[Vdf['Total Individuals Vaccinated'] == max_vaccinated]['State']
lowest_state = Vdf[Vdf['Total Individuals Vaccinated'] == min_vaccinated]['State']
print("State with Highest Vaccinated Population:", highest_state.values[0])
print("State with Least Vaccinated Population:", lowest_state.values[0])

while True:
display_menu()
choice = input("Enter the number of your choice (1 to 6) or '0' to exit: ")

if choice == '0':
print("Exiting...")
break
elif choice in ['1', '2', '3', '4', '5', '6']:
execute_choice(choice)
else:
print("Invalid choice. Please enter a number between 1 and 6, or '0' to exit.")

You might also like