Select Two Columns from a DataFrame

PYSPARK coding challenge · Difficulty: easy · Topic: DataFrame Basics · +50 XP

Problem

Return a DataFrame df_result with only the name and city columns, in that order.

Example Input - `employees`

| name | city | salary |
| --- | --- | --- |
| Asha | Pune | 50000 |
| Ravi | Delhi | 62000 |
| Meera | Pune | 58000 |

Expected Output

| name | city |
| --- | --- |
| Asha | Pune |
| Ravi | Delhi |
| Meera | Pune |

Notes

What this PYSPARK challenge teaches you

“Select Two Columns from a DataFrame” is a easy-level PYSPARK challenge focused on DataFrame Basics. Working through it gives you hands-on practice with beginner — the kind of transformation you are asked to write in real data engineering work and in technical interviews. You can solve it directly in the browser: the dataset is pre-loaded, so you write the query or DataFrame code, run it, and compare your output against the expected result immediately.

Concepts covered

How to approach it

If you get stuck, work through these steps in order before looking at a full solution — each one narrows the problem down:

  1. select() picks columns. Pass the names you want and nothing else.
  2. employees.select('name', 'city') — then call .show() on the result.

How to practise it on PySpark.in

Open the challenge, write your PySpark code in the editor and press Run to execute it against the sample dataset. Submitting checks your output against every test case, including hidden ones, so you find out straight away whether your logic holds up. You can retry as often as you like, and each solved challenge adds to your XP.

Related PYSPARK challenges

Frequently asked questions

Do I need to install Spark or a database to solve this?

No. The PYSPARK environment runs in your browser with the sample data already loaded, so there is nothing to install or configure.

Is this challenge free?

Yes - the problem, the sample dataset, the hints and unlimited test runs are free.

What level is it?

It is rated easy and covers DataFrame Basics.

Solve this challenge free on PySpark.in