# Connect to Google Drive from google.colab import drive drive.mount("/content/gdrive") import csv def load_airbnb_data(filename): """Load Airbnb data from CSV file into a list of dictionaries""" listings = [] # Fields that should be converted to float numeric_fields = [ 'id', 'host_id', 'latitude', 'longitude', 'price', 'minimum_nights', 'number_of_reviews', 'reviews_per_month', 'calculated_host_listings_count', 'availability_365', 'number_of_reviews_ltm' ] with open(filename, 'r', encoding='utf-8') as file: reader = csv.DictReader(file) for row in reader: # Try to convert numeric fields skip_row = False for field in numeric_fields: if field in row and row[field]: # Check if field exists and is not empty try: row[field] = float(row[field]) except ValueError: # Skip this entire row if any numeric conversion fails skip_row = True break else: # Set empty numeric fields to 0.0 row[field] = 0.0 if not skip_row: listings.append(row) return listings # Load the data listings = load_airbnb_data('/content/gdrive/MyDrive/datasets/NYC-Airbnb-2023.csv') print(f"Loaded {len(listings)} listings") print("First 5 listings:") for listing in listings[:5]: print(listing)