Anonymous
Экзамен Datacamp: экзамен Python Associate
Сообщение
Anonymous » 13 ноя 2024, 14:06
Что не так с моей реализацией этой задачи? Не слишком ли я усложняю свой запрос?
Код: Выделить всё
import pandas as pd
import numpy as np
clean_data = pd.read_csv('production_data.csv')
missing_values = ['-', 'missing', 'n/a', 'N/A', 'NA', None]
clean_data['batch_id'] = clean_data['batch_id'].fillna('unknown').astype(str)
clean_data['production_date'] = pd.to_datetime(clean_data['production_date'], errors='coerce')
clean_data['production_date'] = clean_data['production_date'].fillna(pd.to_datetime("2023-01-01"))
clean_data['raw_material_supplier'] = clean_data['raw_material_supplier'].replace({1: 'national_supplier', 2: 'international_supplier'})
clean_data['raw_material_supplier'] = clean_data['raw_material_supplier'].replace(missing_values, 'national_supplier').str.lower().str.strip()
clean_data.loc[~clean_data['raw_material_supplier'].isin(['national_supplier', 'international_supplier']), 'raw_material_supplier'] = 'national_supplier'
clean_data['pigment_type'] = clean_data['pigment_type'].replace(missing_values, 'other').str.lower().str.strip()
clean_data.loc[~clean_data['pigment_type'].isin(['type_a', 'type_b', 'type_c']), 'pigment_type'] = 'other'
clean_data['mixing_speed'] = clean_data['mixing_speed'].replace(missing_values, 'Not Specified').str.capitalize().str.strip()
clean_data.loc[~clean_data['mixing_speed'].isin(['Low', 'Medium', 'High', 'Not Specified']), 'mixing_speed'] = 'Not Specified'
clean_data['pigment_quantity'] = pd.to_numeric(clean_data['pigment_quantity'], errors='coerce')
clean_data['pigment_quantity'] = clean_data['pigment_quantity'].fillna(clean_data['pigment_quantity'].median()).clip(lower=1, upper=100)
clean_data['mixing_time'] = pd.to_numeric(clean_data['mixing_time'], errors='coerce')
clean_data['mixing_time'] = clean_data['mixing_time'].fillna(clean_data['mixing_time'].mean())
clean_data['product_quality_score'] = pd.to_numeric(clean_data['product_quality_score'], errors='coerce')
clean_data['product_quality_score'] = clean_data['product_quality_score'].fillna(clean_data['product_quality_score'].mean()).clip(lower=1, upper=10)
clean_data
По-прежнему поступают отзывы о том, что требования не выполнены: Определите и замените отсутствующие значения. Введите здесь описание изображения
Подробнее здесь:
https://stackoverflow.com/questions/791 ... ciate-exam
1731495991
Anonymous
Что не так с моей реализацией этой задачи? Не слишком ли я усложняю свой запрос? [code]import pandas as pd import numpy as np clean_data = pd.read_csv('production_data.csv') missing_values = ['-', 'missing', 'n/a', 'N/A', 'NA', None] clean_data['batch_id'] = clean_data['batch_id'].fillna('unknown').astype(str) clean_data['production_date'] = pd.to_datetime(clean_data['production_date'], errors='coerce') clean_data['production_date'] = clean_data['production_date'].fillna(pd.to_datetime("2023-01-01")) clean_data['raw_material_supplier'] = clean_data['raw_material_supplier'].replace({1: 'national_supplier', 2: 'international_supplier'}) clean_data['raw_material_supplier'] = clean_data['raw_material_supplier'].replace(missing_values, 'national_supplier').str.lower().str.strip() clean_data.loc[~clean_data['raw_material_supplier'].isin(['national_supplier', 'international_supplier']), 'raw_material_supplier'] = 'national_supplier' clean_data['pigment_type'] = clean_data['pigment_type'].replace(missing_values, 'other').str.lower().str.strip() clean_data.loc[~clean_data['pigment_type'].isin(['type_a', 'type_b', 'type_c']), 'pigment_type'] = 'other' clean_data['mixing_speed'] = clean_data['mixing_speed'].replace(missing_values, 'Not Specified').str.capitalize().str.strip() clean_data.loc[~clean_data['mixing_speed'].isin(['Low', 'Medium', 'High', 'Not Specified']), 'mixing_speed'] = 'Not Specified' clean_data['pigment_quantity'] = pd.to_numeric(clean_data['pigment_quantity'], errors='coerce') clean_data['pigment_quantity'] = clean_data['pigment_quantity'].fillna(clean_data['pigment_quantity'].median()).clip(lower=1, upper=100) clean_data['mixing_time'] = pd.to_numeric(clean_data['mixing_time'], errors='coerce') clean_data['mixing_time'] = clean_data['mixing_time'].fillna(clean_data['mixing_time'].mean()) clean_data['product_quality_score'] = pd.to_numeric(clean_data['product_quality_score'], errors='coerce') clean_data['product_quality_score'] = clean_data['product_quality_score'].fillna(clean_data['product_quality_score'].mean()).clip(lower=1, upper=10) clean_data [/code] По-прежнему поступают отзывы о том, что требования не выполнены: Определите и замените отсутствующие значения. Введите здесь описание изображения Подробнее здесь: [url]https://stackoverflow.com/questions/79184603/datacamp-exam-python-associate-exam[/url]