MulaiMulai sekarang secara gratis

ResultsSets and pandas DataFrames

We can feed a ResultSet directly into a pandas DataFrame, which is the workhorse of many Data Scientists in PythonLand. Jason demonstrated this in the video. In this exercise, you'll follow exactly the same approach to convert a ResultSet into a DataFrame.

Latihan ini adalah bagian dari kursus

Introduction to Databases in Python

Lihat Kursus

Petunjuk latihan

  • Import pandas as pd.
  • Create a DataFrame df using pd.DataFrame() on the ResultSet results.
  • Set the columns of the DataFrame df.columns to be the columns from the first result object results[0].keys().
  • Print the DataFrame.

Latihan interaktif praktis

Cobalah latihan ini dengan menyelesaikan kode contoh berikut.

# import pandas


# Create a DataFrame from the results: df
df = ____

# Set column names
df.columns = ____

# Print the DataFrame
print(____)
Edit dan Jalankan Kode