0% found this document useful (0 votes)
32 views10 pages

Menu

Menu driven program
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)
32 views10 pages

Menu

Menu driven program
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/ 10

MENU DRIVEN PROGRAM

import pandas as pd

import matplotlib.pyplot as plt

P=pd.read_csv("air.csv")

df=pd.DataFrame(P)

print(df)

while True:

print("REAL TIME AIR QUALITY INDEX FROM VARIOUS LOCATIONS")

print("1.Dataframe Statistics")

print("2.Data Visualization as per records")

print("3.Exit")

op=int(input("Enter Your Choice:"))

while True:

#1)DATAFRAME STATISTICS

if op==1:

print("Dateframe satistics")

#1A)DATAFRAME AATRIBUTES

print("1.Dataframe Attributes")

print("2.Dataframe Functions")

print("3.Adding and deleting rows and columns")

print("4.Break")

ch=int(input("Enter your choice"))

while True:

if ch==1:

print("Dataframe Attributes:")

print("1.Diplay the transpose")

print("2.Display column names")

print("3.Display indexes")
print("4.Display the shape")

print("5.Display the dimension")

print("6.Display the data types of all columns")

print("7.Display the size")

print("8.Back")

ch1=int(input("Enter Your Choice:"))

if ch1==1:

print(df.T)

elif ch1==2:

print(df.columns)

elif ch1==3:

print(df.index)

elif ch1==4:

print(df.shape)

elif ch1==5:

print(df.ndim)

elif ch1==6:

print(df.dtypes)

elif ch1==7:

print(df.size)

elif ch1==8:

break

#1B)DATAFRAME FUNCTIONS

elif ch==2:

print("Dataframe Functions:")

print("1. Display Records")

print("2. Display top 5 records")

print("3. Display bottom 5 records")

print("4. Display sum of a column")


print("5.Display the total no of records you wish to see from top")

print("6.Display the total no of records you wish to see from bottom")

print("7.To check whether there is null value in a column")

print("8.Mean of column")

print("9.Mode of column")

print("10. Median of column")

print("11.Break")

ch2=int(input("Enter Your Choice"))

if ch2==1:

print(df)

elif ch2==2:

print(df.head())

elif ch2==3:

print(df.tail())

elif ch2==4:

col=input("Enter a column name")

print(df[col].sum())

elif ch2==5:

n=int(input("Enter no. of records you wish to see from top"))

print(df.head(n))

elif ch2==6:

no=int(input("Enter no. of records you wish to see from bottom"))

print(df.tail(no))

elif ch2==7:

print(df.isnull)

elif ch2==8:

ni=input("Enter a column name")

print(df[ni].mean())

elif ch2==9:
np=input("Enter a column name")

print(df[np].mode())

elif ch2==10:

nr=input("Enter a column name")

print(df[nr].median())

elif ch2==11:

break

#1C)ADDING AND DELETING COLUMNS AND ROWS

elif ch==3:

print("1. Adding a column")

print("2. Deleting a column")

print("3. Adding a row")

print("4. Deleting a row ")

print("5. Break")

ch3=int(input("Enter you Choice"))

if ch3==1:

while True:

print("The following are the methods:")

print("1. using df.loc")

print("2. using df.at")

print("3. using df.assign")

print("4. using syntax df[new column]=[new values]")

coll=input("Enter the column name")

n= int(input("Enter option no."))

a=eval(input("Enter values in the form of list"))

if n==1:

df.loc[: ,coll]=a

print(df)

elif n==2:
df.at[:,col]=a

print(df)

elif n==3:

df=df.assign(coll=n)

print(df)

elif n==4:

df[coll]=a

print(df)

elif n==5:

break

elif ch3==2:

while True:

print("The following are the methods:")

print("1.Drop method")

print("2.Del method")

n1=int(input("enter choice"))

if n1==1:

column_name=input("enter column name")

df.drop(axis=1,labels=column_name,inplace=True)

print(df)

elif n1==2:

column_name=input("enter column name")

del df[column_name]

print(df)

elif n1==3:

break

elif ch3==3:

while True:

print("The following are the options:")


print("1. Using Append")

print("2. Using loc")

print("3. Using at")

n2=int(input("Enter choice"))

if n2==1:

countryy=input("enter country name")

statey=input("enter state")

cityy=input("enter city")

stationn=input("enter station")

last_updatee=eval(input("enter last_update"))

latitudee=eval(input("enter latitude"))

longitudee=eval(input("enter longitude"))

pollutant_idd=eval(input("enter pollutant_id"))

pollutant_minn=eval(input("enter pollutant_min"))

j={'country':countryy,'state':statey,'city':cityy,'station':stationn,

'last_update':last_updatee,'latitude':latitudee,'longitude':longitudee,

'pollutant_id':pollutant_idd,'pollutant_min':pollutant_minn}

df=df.append(j,ignore_index=True)

elif n2==2:

b=int(input("Enter labelled location"))

df.loc[b]=[countryy,statey,cityy,stationn,last_updatee,latitudee,longitude,pollutant_idd,pollutant_minn]

print(df)

elif n2==3:

l=int(input("Enter integer location"))

df.iloc[l]=[countryy,statey,cityy,stationn,last_updatee,latitudee,longitude,pollutant_idd,pollutant_minn]

print(df)

elif n2==4:
break

elif ch3==4:

while True:

print("drop method")

m=int(input("Enter the index of the row "))

df.drop(m,axis=0,inplace=True)

print(df)

elif ch3==5:

break

elif ch==4:

break

#2)DATA VISUALISATION

elif op==2:

print("Data Visualisation")

print("Line chart")

print("Bar chart")

print("Pie chart")

print("Histogram")

print("Scatter chart")

print("Horizontal bar chart")

print(df)

columnname=input("enter column name for x axis")

columnname1=input("enter column name for y axis")

label=input("enter labels")

xlabel=input("enter x label")

ylabel=input("enter y label")

title=input("enter the title")

linestyle1=input("enter linestyle")

linewidth1=input("enter linewidth")
l=input("enter columname for labels")

o=int(input("enter choice"))

if o == 1:

print("line chart")

plt.plot(df[columnname].df[columnname1],label=df[1],linestyle=linestyle1,linewidth=linewidth1)

plt.xlabel(xlabel)

plt.ylabel(ylabel)

plt.title(title)

plt.legend()

plt.show()

elif o == 2:

print("bar chart")

barwidth=int(input("enter barwidth"))

plt.bar(df[columnname].df[columnname1].label=df[1].width=barwidth)

plt.xlabel(xlabel)

plt.ylabel(ylabel)

plt.legend()

plt.grid()

plt.show()

elif o == 3:

print("pie chart")

plt.pie(df[columnname].labels=df[1])

plt.xlabel(xlabel)

plt.legend()

plt.grid()

plt.show()

elif o == 4:

print("histogram")
histtype1=input("enter histtype")

orientation1=input("enter orientation")

plt.hist(df[columnname],bins=20,histtype=histtype1,orientation=orientation1,cumulative=True,label=df[
1])

plt.legend()

plt.grid()

plt.show()

elif o == 5:

print("scatter chart")

plt.scatter(df[columnname].df[columnname1].label=df[1])

plt.legend()

plt.grid()

plt.show()

elif o == 6:

print("multiline chart")

columnnames=input("enter columnname")

plt.plot(df[columnname].df[columnname1].label=df[1].linestyle=linestyle1,linewidth=linewidth1)

plt.plot(df[columnname].df[columnnames].label=df[1],linestyle=linestyle1,linewidth=linewidth1)

plt.xlabel(xlabel)

plt.ylabel(ylabel)

plt.title(title)

plt.legend()

plt.show()

elif o == 7:

print("horizontal bar chart")

barwidth=int(input("enter barwidth"))

plt.barh(df[columnname].df[columnname1].label=df[1].height=barwidth)
plt.xlabel(xlabel)

plt.ylabel(ylabel)

plt.legend()

plt.grid()

plt.show()

#3)THE END

elif op==3:

break

You might also like