Get startedGet started for free

Transforming and cleaning DataFrames

Once data has been curated into a cleaned Python data structure, such as a list of lists, it's easy to convert this into a pandas DataFrame. You'll practice doing just this with the data that was curated in the last exercise.

Per usual, pandas has been imported as pd, and the normalized_testing_scores variable stores the list of each schools testing data, as shown below.

[
    ['01M539', '111 Columbia Street', 'Manhattan', 657.0, 601.0, 601.0],
    ...
]   

This exercise is part of the course

ETL and ELT in Python

View Course

Exercise instructions

  • Create a pandas DataFrame from the list of lists stored in the normalized_testing_scores variable.
  • Set the columns names for the normalized_data DataFrame.

Hands-on interactive exercise

Have a go at this exercise by completing this sample code.

# Create a DataFrame from the normalized_testing_scores list
normalized_data = ____(normalized_testing_scores)

# Set the column names
normalized_data.____ = ["school_id", "street_address", "city", "avg_score_math", "avg_score_reading", "avg_score_writing"]

normalized_data = normalized_data.set_index("school_id")
print(normalized_data.head())
Edit and Run Code