Aan de slagGa gratis aan de slag

Transforming sales data with pandas

Before insights can be extracted from a dataset, column types may need to be altered to properly leverage the data. This is especially common with temporal data types, which can be stored in several different ways.

For this example, pandas has been import as pd and is ready for you to use.

Deze oefening maakt deel uit van de cursus

ETL and ELT in Python

Cursus bekijken

Oefeninstructies

  • Update the transform() function to convert data in the "Order Date" column to type datetime.
  • Filter the DataFrame to only contain rows with "Price Each" less than ten dollars.
  • Print the data types of each column in the DataFrame.

Praktische interactieve oefening

Probeer deze oefening eens door deze voorbeeldcode in te vullen.

raw_sales_data = extract("sales_data.csv")

def transform(raw_data):
    # Convert the "Order Date" column to type datetime
    raw_data["Order Date"] = pd.____(____, format="%m/%d/%y %H:%M")
    
    # Only keep items under ten dollars
    clean_data = raw_data.loc[____, :]
    return clean_data

clean_sales_data = transform(raw_sales_data)

# Check the data types of each column
print(____)
Code bewerken en uitvoeren