0% found this document useful (0 votes)
128 views8 pages

Hotelman

This document defines functions for a hotel management system that allows users to input, display, analyze, delete, and update guest records stored in a CSV file. It imports necessary libraries and defines main and sub-menus for interacting with the different functions. The functions implement pandas to read/write to the CSV, allow analyzing the data through matplotlib plots, and provide data manipulation options.

Uploaded by

Swagata Sharma
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)
128 views8 pages

Hotelman

This document defines functions for a hotel management system that allows users to input, display, analyze, delete, and update guest records stored in a CSV file. It imports necessary libraries and defines main and sub-menus for interacting with the different functions. The functions implement pandas to read/write to the CSV, allow analyzing the data through matplotlib plots, and provide data manipulation options.

Uploaded by

Swagata Sharma
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

import pandas as pd

import matplotlib.pyplot as plt

import csv

import os

main_menu='''\n\n Main Menu-------:

0 To write data

1 To append

2 To display data

3 To analyse data

4 To delete

5 To update

6 Exit'''

display_menu=''' ----Display DATA MENU----

1: All Data

2: First Five Records

3: Last Five Record

4: Specific Id Record

5: Unique meal options

6: Display Selected Columns

7: Return to Main Menu'''

analysis_menu=''' ----Analysis DATA MENU----

1: Line Chart(Net payment/Name of guest)

2: Bar Chart (No. of days/Name of guest)

3: Bar Chart (Age/Name of guest)

4: Pie Chart (Meals preferred/No. of guests) "))

--- Return to Main Menu'''


def display_data():

df=pd.read_csv('c:\HotelManagementSystem\
hotelrecords.csv',names=['Id','Name','Gender','Age','Type_of_room','No._of_days','Source_of_booki
ng','Meals_preferred','Net_payment'],skiprows=1)

while(True):

print(display_menu)

ch=int(input("Enter Choice: "))

if ch==1:

print(df)

elif ch==2:

print(df.head(5))

elif ch==3:

print(df.tail(5))

elif ch==4:

n=int(input('\nEnter ID number for search -> '))

df1=df[df.Id==n]

if df1.empty:

print('\n........No such ID number Available..........\n')

else:

print(df1)

print()

elif ch==5:

print('\nMeal options -> ',df.Meals_preferred.unique())

meals=input('\nEnter meal choice -> ')

df1=df[df.Meals_preferred==meals]

if df1.empty:

print('\nNo such meal options available in -> ',meals)

else:

print(df1)

print()
elif ch==6:

print('\nList of Columns are')

for x in df.columns:

print(x,end=',')

clist=[]

while True:

c=input('\nEnter column name -> ')

clist.append(c)

ch=input('Want to give more column name-> (yes/no) ')

if ch in 'no':

break

print('Details of Selected columns data')

print(df[clist])

print()

else:

break

def input_data():

with open('c:\HotelManagementSystem\hotelrecords.csv', mode='w') as pass_file:

pass_writer = csv.writer(pass_file, delimiter=',')

n=int(input("How many records : "))

for i in range(n):

id=int(input("Enter guest ID:"))

name=input("Name:")

gender=input("Gender: ")

age=int(input("Age: "))

room=input("Type of room: ")

days=int(input("Number of days of stay: "))


source=input("Source of booking: ")

meals=input("Meals preferred: ")

netp=input("Net payment: ")

w=[id,name,gender,age,room,days,source,meals,netp]

pass_writer.writerow(w)

df= pd.read_csv('c:\HotelManagementSystem\
hotelrecords.csv',names=['Id','Name','Gender','Age','Type_of_room','No._of_days','Source_of_booki
ng','Meals_preferred','Net_payment'])

print(df)

def append_data():

with open('c:\HotelManagementSystem\hotelrecords.csv', mode='a') as pass_file:

pass_writer = csv.writer(pass_file, delimiter=',')

id=int(input("Enter guest ID:"))

name=input("Name:")

gender=input("Gender: ")

age=int(input("Age: "))

room=input("Type of room: ")

days=int(input("Number of days of stay: "))

source=input("Source of booking: ")

meals=input("Meals preferred: ")

netp=input("Net payment: ")

a=[id,name,gender,age,room,days,source,meals,netp]

pass_writer.writerow(a)

df = pd.read_csv('c:\HotelManagementSystem\hotelrecords.csv',header=None)

print(df)
def analysis_data():

df = pd.read_csv('c:\HotelManagementSystem\
hotelrecords.csv',names=['Id','Name','Gender','Age','Type_of_room','No._of_days','Source_of_booki
ng','Meals_preferred','Net_payment'],skiprows=1)

while(True):

print(analysis_menu)

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

if ch==1:

df.plot('No._of_days','Net_payment',color='b',linestyle='-',linewidth=2,marker='o',markersize=8)

plt.ylabel('No._of_days',fontsize=12)

plt.xlabel('Net_payment',fontsize=12)

plt.title('No._of_days/Net_payment',fontsize=14)

plt.grid(True)

plt.grid(which='major', linestyle='-', linewidth='0.5', color='red')

plt.show()

elif ch==2:

df.plot.bar('No._of_days','Net_payment',color='g',edgecolor='r')

plt.ylabel('No._of_days',fontsize=12)

plt.xlabel('Net_payment',fontsize=12)

plt.title('No_of_days/Net_payment',fontsize=14)

plt.show()

elif ch==3:

df.plot.bar('Age','No._of_days',color='g',edgecolor='r')

plt.ylabel('Age',fontsize=12)

plt.xlabel('No._of_days',fontsize=12)

plt.title('Age/No._of_days',fontsize=14)

plt.show()
elif ch==4:

plt.pie(df.Age, labels=df.Net_payment,autopct='%.1f%%')

else:

break

def remove_data():

df = pd.read_csv('c:\HotelManagementSystem\
hotelrecords.csv',names=['Id','Name','Gender','Age','Type_of_room','No._of_days','Source_of_booki
ng','Meals_preferred','Net_payment'])

print(df)

n=int(input('Enter the row index number for deletion -> '))

df.drop(n,inplace=True)

print(df)

print('\n------------Record deleted from Data Frame---------------')

ch=input("Want to change in CSV file (yes/no]")

if ch in 'yes':

df.to_csv(r"C:\HotelManagementSystem\hotelrecords.csv",index=False,sep=',')

print('\nData Written in [new_pass.csv] file.........\n\n')

os.remove("c:\HotelManagementSystem\hotelrecords.csv")

os.rename(r"c:\HotelManagementSystem\hotelrecords.csv",r"c:\HotelManagementSystem\
hotelrecords.csv")

def update_data():

df = pd.read_csv('c:\HotelManagementSystem\
hotelrecords.csv',names=['Id','Name','Gender','Age','Type_of_room','No._of_days','Source_of_booki
ng','Meals_preferred','Net_payment'])

print(df)

n=int(input('Enter index number for updation -> '))

id=int(input('Enter guest ID for updation (it should be of same index) -> '))

ns1=int(input('Enter additional days of stay of guest -> '))


cap=df.loc[n].at['Net_payment']

print(cap)

if ns1<int(cap):

df.loc[df['Id'] == Id, 'No._of_days'] = ns1

print(df)

ch=input("Want to change in CSV file")

if ch in 'yY':

df.to_csv(r"C:\HotelManagementSystem\hotelrecords.csv",index=False,sep=',')

print('\nData Written in [new_pass.csv] file.........\n\n')

os.remove("c:\HotelManagementSystem\hotelrecords.csv")

os.rename(r"c:\\HotelManagementSystem\hotelrecords.csv",r"c:\HotelManagementSystem\
hotelrecords.csv")

print('\n------------Record Modified---------------')

else:

print("------Number of days cannot exceed initial net payment amount package ------")

print(df)

while(True):

print(main_menu)

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

if choice==0:

input_data()

elif choice==1:

append_data()

elif choice==2:
display_data()

elif choice==3:

analysis_data()

elif choice==4:

remove_data()

elif choice==5:

update_data()

elif choice==6:

print("Ending Project")

break

You might also like