import pandas as pd
import [Link] as plt
print('===============Sree Ayyappa Public School================')
print('= =')
print('= Welcome to Books Module =')
print('= =')
print('=================================================')
dfbooks = pd.read_csv('[Link]',
header=None,
names=['bookno','name','author','category'])
choice = 0
while(choice != 6):
print('Choices for the module')
print('1. Add a new Book')
print('2. Update Book')
print('3. Delete Book')
print('4. View books')
print('5. View Charts')
print('6. Exit')
choice = int(input('Enter your choice : '))
if(choice == 1):
bookno = int(input('Input Book Number : '))
name = input('Input book Name : ')
author = input('Input mobile number : ')
category = input('Input category : ')
noofbooks = len(dfbooks)
[Link][noofbooks] = [bookno,name,author,category]
print(dfbooks)
dfbooks.to_csv('[Link]',header=False,index=False)
elif (choice == 2):
bookno = int(input('Enter books bookno : '))
print([Link][dfbooks['bookno'] == bookno])
indexno = [Link][dfbooks['bookno'] == bookno].index
print('1. Update books bookno')
print('2. Update Name')
print('3. Update author')
print('4. Update category')
updatechoice = int(input('Enter your choice for update : '))
if (updatechoice == 1):
newbookno = int(input('Enter new books bookno : '))
[Link][indexno,'bookno'] = newbookno
dfbooks.to_csv('[Link]',header=False,index=False)
elif (updatechoice == 2):
newempname = input('Enter updated books Name : ')
[Link][indexno,'name'] = newempname
dfbooks.to_csv('[Link]',header=False,index=False)
elif (updatechoice == 3):
newempauthor = input('Enter updated books author : ')
[Link][indexno,'author'] = newempauthor
dfbooks.to_csv('[Link]',header=False,index=False)
elif (updatechoice == 4):
newbooks = input('Enter updated books category : ')
[Link][indexno,'category'] = newbooks
dfbooks.to_csv('[Link]',header=False,index=False)
print([Link][dfbooks['bookno'] == bookno])
print('----books Record Updated ------ ')
elif (choice == 3):
bookno = int(input('Enter books bookno : '))
print([Link][dfbooks['bookno'] == bookno])
indexno = [Link][dfbooks['bookno'] == bookno].index
confirm = input('Are you sure you want to delete it (Y/N) : ')
if (confirm == 'Y' or confirm == 'y'):
dfbooks = [Link](indexno)
dfbooks.to_csv('[Link]',header=False,index=False)
print('---------- Record Deleted ----------------- ')
elif (choice == 4):
print('1. Display all ')
print('2. Display top records')
print('3. Display bottom records')
print('4. Display on the basis of author')
print('5. Display on the basis of category')
dispchoice = int(input('Enter your choice'))
if (dispchoice == 1):
print(dfbooks)
elif (dispchoice == 2):
top = int(input('Enter how many top records to be displayed : '))
print([Link](top))
elif (dispchoice == 3):
bottom = int(input('Enter how many bottom records to be displayed : '))
print([Link](bottom))
elif (dispchoice == 4):
author = input('Enter author to search : ')
print([Link][dfbooks['author'] == author])
elif (dispchoice == 5):
category = input('Enter category to search : ')
print([Link][dfbooks['category'] == category])
elif (choice == 5):
print('1. Bar Chart - category wise books')
print('2. Line Chart - category wise books')
print('3. Back Menu')
chartchoice = int(input('Enter your choice : '))
if (chartchoice == 1):
dftemp = [Link] ('category').aggregate('count')
categorys = [Link].to_list()
categorycount = dftemp['bookno']
[Link](categorys,categorycount)
[Link]('Category')
[Link]('Total books')
[Link]('Category Wise books')
[Link]()
elif (chartchoice == 2):
dftemp = [Link] ('category').aggregate('count')
categorys = [Link].to_list()
categorycount = dftemp['bookno']
[Link](categorys,categorycount)
[Link]('Category')
[Link]('Total books')
[Link]('Category Wise books')
[Link]()
print(' ')