Editor

DataFrame from Records

Intermediate · Write the code · from Pandas: Create, Load, and Explore DataFrames

From the lesson: Pandas: Create, Load, and Explore DataFrames

You have a spreadsheet with 10,000 rows of sales data. You need to find every order over $500, group them by region, and calculate the average. In Excel, that takes a pivot table, a filter, and a lot of clicking. In pandas, it takes three lines of code.

Read the lesson

Create a DataFrame called df from a list of dictionaries representing three students:

  • {'name': 'Alice', 'grade': 90}
  • {'name': 'Bob', 'grade': 85}
  • {'name': 'Charlie', 'grade': 92}
  • Print the shape of the DataFrame using print(df.shape).

    import pandas as pd
    # Create DataFrame from a list of dicts

    More Pandas DataFrame exercises

    All Python exercises · 50 practice problems · Data Science & Machine Learning quiz