Dataford
Interview QuestionsInterview GuidesExperiencesCoaching
New
Pricing
Get started
Dataford
Popular roles
Software EngineerData AnalystData ScientistData EngineerBusiness AnalystAI EngineerMachine Learning EngineerProduct Manager
Browse
Browse All RolesEvery role hub, from analyst to MLBrowse All CompaniesCompany-specific interview loopsAll Interview GuidesThe full guide library
Top questions by role
Software EngineerData AnalystData ScientistData EngineerBusiness AnalystAI EngineerMachine Learning EngineerProduct Manager
Top questions by skill
SQLPythonStatisticsMachine LearningA/B TestingSystem DesignGenerative AIProduct SenseMetricsBehavioral
Browse all questions →Try a mock interview
Experiences
Practice
Mock InterviewsTimed interview simulations with feedbackCoaching1:1 coaching with people at your target companiesSuccess PathYour 6-week structured planModulesCurated lessons by topicWebinarsTalks from ex-Big Tech data leadsPlaygroundA free-form scratch editor
Learn
BlogInterview strategy and career adviceTech Job Market ReportHiring trends across data and AI rolesFor UniversitiesDataford for career centersAbout DatafordWho we are and how we build
Pricing
Build my plan
Normalize Energy Usage Data from CSV
00:00
5 left

Normalize Energy Usage Data from CSV

EasyPython

Problem

You are given a complex CSV file representing energy usage data, where each row contains the following fields: timestamp, location, energy_usage_kwh, and energy_type. Your task is to parse this CSV data and normalize the energy_usage_kwh by converting it to megawatt-hours (MWh) and rounding to two decimal places. Additionally, filter out entries with negative energy usage values.

Input

  • A string csv_data representing the CSV content.

Output

  • A list of dictionaries, where each dictionary contains the normalized energy usage data with keys timestamp, location, and energy_usage_mwh.

Examples

Example 1:

Input: "timestamp,location,energy_usage_kwh,energy_type
2023-01-01T00:00:00Z,LocationA,1500,solar
2023-01-01T01:00:00Z,LocationB,-500,wind"  
Output: [{'timestamp': '2023-01-01T00:00:00Z', 'location': 'LocationA', 'energy_usage_mwh': 1.5}]

Example 2:

Input: "timestamp,location,energy_usage_kwh,energy_type
2023-01-01T00:00:00Z,LocationC,3000,solar"  
Output: [{'timestamp': '2023-01-01T00:00:00Z', 'location': 'LocationC', 'energy_usage_mwh': 3.0}]

Constraints

  • The CSV will have at least one valid row.
  • The energy_usage_kwh values are integers, which can be negative or positive.

Constraints

  • The CSV will have at least one valid row.
  • The energy_usage_kwh values are integers, which can be negative or positive.

Function Signature

def normalize_energy_usage(csv_data):
Interviewer

Your question is Normalize Energy Usage Data from CSV. Start with the requirements in the Question tab.

Run and submit as often as you like. When you're ready, talk me through your approach or go straight to the code.

You need to log in / sign up to run or submit.
CodePython 3
Sign up free to run your codeLog inLn 2
Run your code to see test output here.