Menu
CoddyTech

Select Columns

Part of the Fundamentals section of Coddy's PySpark journey. Lesson 4 of 18.

A DataFrame is immutable: selecting columns returns a new DataFrame and leaves the original available. Use df.select("city", "score") to keep those columns in that order. Selecting a column does not filter out any rows.

places.select("city", "score")

For these challenges, write the Python function transform(df). The checker supplies a DataFrame and checks the one you return. You do not need to create a session or print the result.

challenge icon

Challenge

Easy

Keep only item and price, in that order. Keep every row.

Write transform(df) and return a Spark DataFrame. The checker supplies df with schema item string, price int, stock int. The session and F (PySpark functions) are already available. Do not print; the checker displays the returned rows. Return columns in this order: item, price.

Try it yourself

def transform(df):
    return df
quiz iconTest yourself

This lesson includes a short quiz. Start the lesson to answer it and track your progress.

All lessons in Fundamentals

Practice on your own: Online Python compiler