0 out of 68 challenges solved

Read a CSV file and extracts data from specific columns

Question:
Write a function called read_csv_file that takes a file path and a list of column names as input, and returns a list of dictionaries containing the data from the specified columns in the CSV file. The function should read the CSV file, extract the data from the specified columns, and return a list of dictionaries where each dictionary represents a row of data.

Example:
Input:
File Path: "data.csv"
Columns: ["Name", "Age", "City"]
Output: [{"Name": "John", "Age": "25", "City": "New York"}, {"Name": "Emma", "Age": "30", "City": "London"}]

import csv

def read_csv_file(file_path, columns):
    """
    Reads a CSV file and extracts data from specific columns.

    Args:
    file_path (str): The path to the CSV file.
    columns (list): The list of column names to extract data from.

    Returns:
    list: A list of dictionaries containing the data from the specified columns.
    """
    # TODO: Implement the read_csv_file function
    pass