Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import pandas as pd
- data = pd.read_csv("assets/hotels.csv")
- print(data)
- class Hotel:
- def __init__(self, hotelID):
- self.hotel_id = hotelID
- def Book(self):
- pass
- def isAvailable(self):
- print("Hotel ID: " + self.hotel_id)
- available = data.loc[data["id"] == self.hotel_id, "available"]
- print("available: ")
- print(available)
- if available == "yes":
- return True
- else:
- return False
- class BookingTicket:
- def __init__(self, cust_name, hotel):
- pass
- def Generate(self):
- pass
- if __name__ == "__main__":
- hotel = Hotel("134")
- hotel.isAvailable()
Advertisement
Comments
-
- The error was that it was getting the id data as int and I was trying to pass in a string:
- Error:
- Traceback (most recent call last):
- File "E:\PythonProjects\py_apps\py_hotelBooking\main.py", line 35, in <module>
- hotel.isAvailable()
- File "E:\PythonProjects\py_apps\py_hotelBooking\main.py", line 20, in isAvailable
- if available == "yes":
- ^^^^^^^^^^^^^^^^^^
- File "E:\PythonProjects\py_apps\py_hotelBooking\.venv\Lib\site-packages\pandas\core\generic.py", line 1577, in __nonzero__
- raise ValueError(
- ValueError: The truth value of a DataFrame is ambiguous. Use a.empty, a.bool(), a.item(), a.any() or a.all().
- Fix:
- add the "dtype=str" to the parameter so that it reads everything as string
- df = pd.read_csv("assets/hotels.csv", dtype=str)
Add Comment
Please, Sign In to add comment