import csv import random def generate_office_rent_data(): # 定义可能的值 cities = ["1", "2", "3", "4"] districts = { "1": ["1", "2", "3", "4"], "2": ["1", "2", "3", "4"], "3": ["1", "2", "3", "4"], "4": ["1", "2", "3", "4"] } directions = [1, 2, 3, 4] fitments = [1, 2, 3] near_facilities =[1, 2, 3, 4] lease_terms = [1, 2, 3, 4] office_grades = [1, 2, 3] data = [] for _ in range(10000): city = random.choice(cities) district = random.choice(districts[city]) area = round(random.uniform(50, 300), 2) # 面积在50到300平方米之间 floor = random.randint(1, 30) direction = random.choice(directions) fitment = random.choice(fitments) near_facility = random.choice(near_facilities) lease_term = random.choice(lease_terms) rent_price = round(random.uniform(5000, 50000), 2) # 租金在5000到50000之间 office_grade = random.choice(office_grades) building_age = random.randint(1, 50) # 建筑年龄 free_rent_period = round(random.uniform(0, 3), 2) # 免租期,0到3个月 parking_spaces = random.randint(0, 49) # 停车位数量 elevators = random.randint(1, 10) # 电梯数量 green_building = random.randint(0, 1) # 是否是绿色建筑 management_fee = round(random.uniform(0, 1000), 2) # 管理费 data.append([ area, city, district, floor, direction, fitment, near_facility, lease_term, rent_price, office_grade, building_age, free_rent_period, parking_spaces, elevators, green_building, management_fee ]) # 写入CSV文件 with open('data.csv', 'w', newline='', encoding='utf-8') as file: writer = csv.writer(file) # 写入标题行 writer.writerow([ "area", "city", "district", "floor", "direction", "fitment", "near_facilities", "lease_term", "rent_price", "office_grade", "building_age", "free_rent_period", "parking_spaces", "elevators", "green_building", "management_fee" ]) # 写入数据 writer.writerows(data) print("Data has been generated and written to data.csv") if __name__ == "__main__": generate_office_rent_data()