Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started

Normalize Energy Usage Data from CSV

EasyPython00:00
Practice interviewer
In session
5 left
00:00

Your question is Normalize Energy Usage Data from CSV. Start with the requirements on the right.

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.

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):
Your solutionPython 3
You need to log in / sign up to run or submit.
Run your code to see test output