0% found this document useful (0 votes)
17 views4 pages

Code 7import Pandas As PD

This document defines classes for guests, reservations, and a guest tracker. The guest tracker class manages a list of guests and can generate a guest report as a Pandas DataFrame with guest details. It also includes a method to generate a bar chart using Matplotlib showing the number of guests by room type. This provides easy analysis and visualization of guest tracking data.

Uploaded by

Harrison Adom
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)
17 views4 pages

Code 7import Pandas As PD

This document defines classes for guests, reservations, and a guest tracker. The guest tracker class manages a list of guests and can generate a guest report as a Pandas DataFrame with guest details. It also includes a method to generate a bar chart using Matplotlib showing the number of guests by room type. This provides easy analysis and visualization of guest tracking data.

Uploaded by

Harrison Adom
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/ 4

import pandas as pd

import matplotlib.pyplot as plt

class Guest:

def __init__(self, name, email, reservation):

self.name = name

self.email = email

self.reservation = reservation

class Reservation:

def __init__(self, room_type, check_in_date, check_out_date):

self.room_type = room_type

self.check_in_date = check_in_date

self.check_out_date = check_out_date

class GuestTracker:

def __init__(self):

self.guests = []

def add_guest(self, guest):

self.guests.append(guest)

def remove_guest(self, guest):

self.guests.remove(guest)

def get_guest_by_email(self, email):

for guest in self.guests:

if guest.email == email:

return guest
return None

def get_guests_by_date_range(self, start_date, end_date):

result = []

for guest in self.guests:

reservation = guest.reservation

if reservation.check_in_date >= start_date and reservation.check_out_date <= end_date:

result.append(guest)

return result

def generate_report(self):

data = []

for guest in self.guests:

data.append({

'Name': guest.name,

'Email': guest.email,

'Room Type': guest.reservation.room_type,

'Check-in Date': guest.reservation.check_in_date,

'Check-out Date': guest.reservation.check_out_date

})

df = pd.DataFrame(data)

return df

def generate_guests_by_room_type_chart(self):

room_types = []

counts = []

for guest in self.guests:

room_type = guest.reservation.room_type

if room_type in room_types:
index = room_types.index(room_type)

counts[index] += 1

else:

room_types.append(room_type)

counts.append(1)

plt.bar(room_types, counts)

plt.xlabel('Room Type')

plt.ylabel('Guest Count')

plt.title('Guests by Room Type')

plt.show()

# Example usage

reservation1 = Reservation('Standard', '2023-07-10', '2023-07-15')

guest1 = Guest('Harrison Adom', '[email protected]', reservation1)

reservation2 = Reservation('Deluxe', '2023-07-12', '2023-07-17')

guest2 = Guest('Robert Zigah', '[email protected]', reservation2)

tracker = GuestTracker()

tracker.add_guest(guest1)

tracker.add_guest(guest2)

# Generate guest report

guest_report = tracker.generate_report()

print(guest_report)

# Generate guests by room type chart

tracker.generate_guests_by_room_type_chart()
# we've added two new methods to the GuestTracker class: generate_report and
generate_guests_by_room_type_chart.

The generate_report method converts the guest data into a pandas DataFrame and returns it. This
allows you to easily analyze and manipulate the guest data using pandas' rich functionality.

The generate_guests_by_room_type_chart method generates a bar chart using matplotlib to visualize


the number of guests in each room typ

You might also like