LAB 04.02 - BUILDING DATASETS #330
ljaimesm74
started this conversation in
04 - GESTIÓN DE DATOS
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
mi codigo de prueba:
import pandas as pd
Get building ID and date for the student
bid, date = 900, '2016-02-01' # Example values, replace with actual logic
print("your building_id", bid)
print("your date ", date)
Load the data from the CSV files
building_metadata = pd.read_csv('building_metadata.csv')
weather_train = pd.read_csv('weather_train.csv')
train = pd.read_csv('train.csv')
Filter data for the given building_id and date
building_data = building_metadata[building_metadata['building_id'] == bid]
weather_data = weather_train[(weather_train['site_id'] == building_data['site_id'].values[0]) & (weather_train['timestamp'].str.startswith(date))]
meter_data = train[(train['building_id'] == bid) & (train['timestamp'].str.startswith(date)) & (train['meter'] == 0)]
Merge dataframes to get the required columns
merged_data = meter_data.merge(weather_data, on='timestamp', how='left').merge(building_data, on='building_id', how='left')
Select the required columns
required_columns = ['meter_reading', 'air_temperature', 'cloud_coverage', 'dew_temperature',
'precip_depth_1_hr', 'sea_level_pressure', 'wind_direction', 'wind_speed',
'square_feet', 'year_built']
filtered_data = merged_data[required_columns]
Fill any missing values with zero
filtered_data.fillna(0, inplace=True)
Extract the column of the target variable and sum all values
sumY = int(filtered_data['meter_reading'].sum())
Sum all the values of the rest of the columns
sumX = int(filtered_data.drop(columns=['meter_reading']).sum().sum())
sumX, sumY
Resultado:
your building_id 900
your date 2016-02-01
:29: SettingWithCopyWarning:
A value is trying to be set on a copy of a slice from a DataFrame
See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy
filtered_data.fillna(0, inplace=True)
(2705206, 4941)
Pero al hacer lo mismo para:
Get building ID and date for the student
bid, date = 911, '2016-02-12' # Example values, replace with actual logic
print("your building_id", bid)
print("your date ", date)
Load the data from the CSV files
building_metadata = pd.read_csv('building_metadata.csv')
weather_train = pd.read_csv('weather_train.csv')
train = pd.read_csv('train.csv')
Filter data for the given building_id and date
building_data = building_metadata[building_metadata['building_id'] == bid]
weather_data = weather_train[(weather_train['site_id'] == building_data['site_id'].values[0]) & (weather_train['timestamp'].str.startswith(date))]
meter_data = train[(train['building_id'] == bid) & (train['timestamp'].str.startswith(date)) & (train['meter'] == 0)]
Merge dataframes to get the required columns
merged_data = meter_data.merge(weather_data, on='timestamp', how='left').merge(building_data, on='building_id', how='left')
Select the required columns
required_columns = ['meter_reading', 'air_temperature', 'cloud_coverage', 'dew_temperature',
'precip_depth_1_hr', 'sea_level_pressure', 'wind_direction', 'wind_speed',
'square_feet', 'year_built']
filtered_data = merged_data[required_columns]
Fill any missing values with zero
filtered_data.fillna(0, inplace=True)
Extract the column of the target variable and sum all values
sumY = int(filtered_data['meter_reading'].sum())
Sum all the values of the rest of the columns
sumX = int(filtered_data.drop(columns=['meter_reading']).sum().sum())
sumX, sumY
Da el resultado:
your building_id 911
your date 2016-02-12
:29: SettingWithCopyWarning:
A value is trying to be set on a copy of a slice from a DataFrame
See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy
filtered_data.fillna(0, inplace=True)
(5778391, 7965)
Pero, la calificacion es cero
task_01 submitted. your grade is 0
----- grader message -------
checking for building_id=911 and date='2016-02-12'
incorrect
Can you help?
Beta Was this translation helpful? Give feedback.
All reactions