Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Вивчайте Challenge: Room Selection Tool | Architectural Data Analysis with Python
Practice
Projects
Quizzes & Challenges
Quizzes
Challenges
/
Python for Architects

bookChallenge: Room Selection Tool

In architectural practice, you often need to select rooms based on specific requirements such as minimum area and occupancy. Using Python and the pandas library, you can efficiently filter and sort room data to meet these criteria. Imagine you have a DataFrame representing various rooms in a building, with columns for the room name, its area in square meters, and its occupancy capacity.

123456789101112131415161718192021
import pandas as pd # Hardcoded DataFrame of rooms data = { "Room": ["Conference", "Office1", "Office2", "Lounge", "Storage", "Lab"], "Area": [35, 20, 28, 40, 15, 30], "Occupancy": [10, 2, 3, 8, 1, 5] } rooms_df = pd.DataFrame(data) def select_rooms(df): # Filter rooms by area > 25 and occupancy >= 3 filtered = df[(df["Area"] > 25) & (df["Occupancy"] >= 3)] # Sort by area in descending order sorted_rooms = filtered.sort_values(by="Area", ascending=False) # Return list of room names return sorted_rooms["Room"].tolist() # Example usage selected = select_rooms(rooms_df) print(selected)
copy

This function first filters the DataFrame to include only those rooms where the area is greater than 25 square meters and the occupancy is at least 3. It then sorts the filtered rooms by area in descending order and returns a list of the room names that meet these criteria. This approach allows you to quickly identify which rooms are suitable for larger groups or specific activities, making architectural planning more efficient.

Завдання

Swipe to start coding

Write a function called select_rooms that takes a pandas DataFrame with columns 'Room', 'Area', and 'Occupancy'. The function should:

  • Filter the DataFrame to include only rooms where area is greater than 25.
  • Further filter to include only rooms where occupancy is at least 3.
  • Sort the resulting rooms by area in descending order.
  • Return a list of the room names in this order.

Test your function with the following DataFrame:

import pandas as pd

data = {
    "Room": ["Conference", "Office1", "Office2", "Lounge", "Storage", "Lab"],
    "Area": [35, 20, 28, 40, 15, 30],
    "Occupancy": [10, 2, 3, 8, 1, 5]
}
rooms_df = pd.DataFrame(data)

Рішення

Все було зрозуміло?

Як ми можемо покращити це?

Дякуємо за ваш відгук!

Секція 1. Розділ 7
single

single

Запитати АІ

expand

Запитати АІ

ChatGPT

Запитайте про що завгодно або спробуйте одне із запропонованих запитань, щоб почати наш чат

Suggested prompts:

Can you explain how to adjust the filtering criteria for different area or occupancy requirements?

What if I want to include additional room attributes in the selection process?

How can I modify the function to return more details about each selected room?

close

bookChallenge: Room Selection Tool

Свайпніть щоб показати меню

In architectural practice, you often need to select rooms based on specific requirements such as minimum area and occupancy. Using Python and the pandas library, you can efficiently filter and sort room data to meet these criteria. Imagine you have a DataFrame representing various rooms in a building, with columns for the room name, its area in square meters, and its occupancy capacity.

123456789101112131415161718192021
import pandas as pd # Hardcoded DataFrame of rooms data = { "Room": ["Conference", "Office1", "Office2", "Lounge", "Storage", "Lab"], "Area": [35, 20, 28, 40, 15, 30], "Occupancy": [10, 2, 3, 8, 1, 5] } rooms_df = pd.DataFrame(data) def select_rooms(df): # Filter rooms by area > 25 and occupancy >= 3 filtered = df[(df["Area"] > 25) & (df["Occupancy"] >= 3)] # Sort by area in descending order sorted_rooms = filtered.sort_values(by="Area", ascending=False) # Return list of room names return sorted_rooms["Room"].tolist() # Example usage selected = select_rooms(rooms_df) print(selected)
copy

This function first filters the DataFrame to include only those rooms where the area is greater than 25 square meters and the occupancy is at least 3. It then sorts the filtered rooms by area in descending order and returns a list of the room names that meet these criteria. This approach allows you to quickly identify which rooms are suitable for larger groups or specific activities, making architectural planning more efficient.

Завдання

Swipe to start coding

Write a function called select_rooms that takes a pandas DataFrame with columns 'Room', 'Area', and 'Occupancy'. The function should:

  • Filter the DataFrame to include only rooms where area is greater than 25.
  • Further filter to include only rooms where occupancy is at least 3.
  • Sort the resulting rooms by area in descending order.
  • Return a list of the room names in this order.

Test your function with the following DataFrame:

import pandas as pd

data = {
    "Room": ["Conference", "Office1", "Office2", "Lounge", "Storage", "Lab"],
    "Area": [35, 20, 28, 40, 15, 30],
    "Occupancy": [10, 2, 3, 8, 1, 5]
}
rooms_df = pd.DataFrame(data)

Рішення

Switch to desktopПерейдіть на комп'ютер для реальної практикиПродовжуйте з того місця, де ви зупинились, використовуючи один з наведених нижче варіантів
Все було зрозуміло?

Як ми можемо покращити це?

Дякуємо за ваш відгук!

Секція 1. Розділ 7
single

single

some-alt