MulaiMulai sekarang secara gratis

From SQLAlchemy results to a plot

We can also take advantage of pandas and Matplotlib to build figures of our data. Remember that data visualization is essential for both exploratory data analysis and communication of your data!

Latihan ini adalah bagian dari kursus

Introduction to Databases in Python

Lihat Kursus

Petunjuk latihan

  • Import matplotlib.pyplot as plt.
  • Create a DataFrame df using pd.DataFrame() on the provided results.
  • Set the columns of the DataFrame df.columns to be the columns from the first result object results[0].keys().
  • Print the DataFrame df.
  • Use the plot.bar() method on df to create a bar plot of the results.
  • Display the plot with plt.show().

Latihan interaktif praktis

Cobalah latihan ini dengan menyelesaikan kode contoh berikut.

# Import pyplot as plt from matplotlib


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

# Set Column names
df.columns = ____

# Print the DataFrame


# Plot the DataFrame

Edit dan Jalankan Kode