Create a Student DataFrame from a List

Quick Overview

Create a pandas DataFrame from a two-dimensional list of student IDs and ages. Use the exact student_id and age columns while preserving the original row order and returning a DataFrame.

Create a Student DataFrame from a List

Company: Microsoft

Role: Software Engineer

Category: Data Manipulation (SQL/Python)

Difficulty: easy

Interview Round: Other

### Problem Implement the pandas function below to construct a DataFrame from `student_data`, a two-dimensional list containing student IDs and ages. ```python def createDataframe(student_data: List[List[int]]) -> pd.DataFrame: ... ``` Each row supplies a student ID followed by an age. Return a DataFrame with columns `student_id` and `age`, in that order. Keep the rows in the same order as the input list. ### Examples **Example 1:** Input: ```python student_data = [[12, 16], [4, 10], [9, 16]] ``` Returned DataFrame values: | student_id | age | |---|---| | 12 | 16 | | 4 | 10 | | 9 | 16 | The row starting with `12` stays first even though `4` is smaller. **Example 2:** Input: ```python student_data = [[25, 19]] ``` Returned DataFrame values: | student_id | age | |---|---| | 25 | 19 | A single input row still produces a DataFrame with both named columns. ### Constraints and Clarifications - The supplied signature uses a two-dimensional list of integers. - The first value of each row is the student ID; the second is the age. - Return a pandas DataFrame, not the original list or a printed table. - Preserve input row order. Do not sort by student ID or age. - The source gives no numeric bounds, row-count bounds, uniqueness guarantee, explicit dtype requirement, or custom index requirement. Do not add validation rules for those unspecified properties. ```hint Name the two columns Use the relationship between the two values in each input row and the two requested column labels. ``` ### What a Strong Answer Covers - Construct a DataFrame with the exact labels `student_id` and `age`. - Preserve the input rows and their order. - Keep column labels separate from the integer data rows. ### Follow-up Questions - Why would sorting the result violate this task even if all rows remained present? - How would reversing the two column labels change the meaning of the result?

Overview: Create a pandas DataFrame from a two-dimensional list of student IDs and ages. Use the exact student_id and age columns while preserving the original row order and returning a DataFrame.

Microsoft logo
Microsoft
easySoftware EngineerOtherData Manipulation (SQL/Python)
0
0

Problem

Implement the pandas function below to construct a DataFrame from student_data, a two-dimensional list containing student IDs and ages.

def createDataframe(student_data: List[List[int]]) -> pd.DataFrame:
    ...

Each row supplies a student ID followed by an age. Return a DataFrame with columns student_id and age, in that order. Keep the rows in the same order as the input list.

Examples

Example 1:

Input:

student_data = [[12, 16], [4, 10], [9, 16]]

Returned DataFrame values:

student_idage
1216
410
916

The row starting with 12 stays first even though 4 is smaller.

Example 2:

Input:

student_data = [[25, 19]]

Returned DataFrame values:

student_idage
2519

A single input row still produces a DataFrame with both named columns.

Constraints and Clarifications

  • The supplied signature uses a two-dimensional list of integers.
  • The first value of each row is the student ID; the second is the age.
  • Return a pandas DataFrame, not the original list or a printed table.
  • Preserve input row order. Do not sort by student ID or age.
  • The source gives no numeric bounds, row-count bounds, uniqueness guarantee, explicit dtype requirement, or custom index requirement. Do not add validation rules for those unspecified properties.

What a Strong Answer Covers Guidance

  • Construct a DataFrame with the exact labels student_id and age .
  • Preserve the input rows and their order.
  • Keep column labels separate from the integer data rows.

Follow-up Questions Guidance

  • Why would sorting the result violate this task even if all rows remained present?
  • How would reversing the two column labels change the meaning of the result?