shahilsaha

py_bookingApp

Aug 21st, 2024 (edited)
30
0
Never
1
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.69 KB | Source Code | 0 0
  1. import pandas as pd
  2.  
  3. data = pd.read_csv("assets/hotels.csv")
  4. print(data)
  5.  
  6.  
  7. class Hotel:
  8.  
  9.     def __init__(self, hotelID):
  10.         self.hotel_id = hotelID
  11.  
  12.     def Book(self):
  13.         pass
  14.  
  15.     def isAvailable(self):
  16.         print("Hotel ID: " + self.hotel_id)
  17.         available = data.loc[data["id"] == self.hotel_id, "available"]
  18.         print("available: ")
  19.         print(available)
  20.         if available == "yes":
  21.             return True
  22.         else:
  23.             return False
  24.  
  25.  
  26. class BookingTicket:
  27.     def __init__(self, cust_name, hotel):
  28.         pass
  29.  
  30.     def Generate(self):
  31.         pass
  32.  
  33. if __name__ == "__main__":
  34.     hotel = Hotel("134")
  35.     hotel.isAvailable()
Advertisement
Comments
  • shahilsaha
    336 days
    # text 0.76 KB | 0 0
    1. The error was that it was getting the id data as int and I was trying to pass in a string:
    2.  
    3. Error:
    4.  
    5. Traceback (most recent call last):
    6. File "E:\PythonProjects\py_apps\py_hotelBooking\main.py", line 35, in <module>
    7. hotel.isAvailable()
    8. File "E:\PythonProjects\py_apps\py_hotelBooking\main.py", line 20, in isAvailable
    9. if available == "yes":
    10. ^^^^^^^^^^^^^^^^^^
    11. File "E:\PythonProjects\py_apps\py_hotelBooking\.venv\Lib\site-packages\pandas\core\generic.py", line 1577, in __nonzero__
    12. raise ValueError(
    13. ValueError: The truth value of a DataFrame is ambiguous. Use a.empty, a.bool(), a.item(), a.any() or a.all().
    14.  
    15. Fix:
    16.  
    17. add the "dtype=str" to the parameter so that it reads everything as string
    18. df = pd.read_csv("assets/hotels.csv", dtype=str)
    19.  
Add Comment
Please, Sign In to add comment