ÎncepețiÎncepe gratuit

Adaugă statistici sumare la graficul seriei de timp

Este posibil să vizualizezi grafice ale seriilor de timp împreună cu sumare numerice într-un singur grafic, folosind API-ul pandas pentru matplotlib și metoda table:

# Plot the time series data in the DataFrame
ax = df.plot()

# Compute summary statistics of the df DataFrame
df_summary = df.describe()

# Add summary table information to the plot
ax.table(cellText=df_summary.values, 
         colWidths=[0.3]*len(df.columns), 
         rowLabels=df_summary.index, 
         colLabels=df_summary.columns, 
         loc='top')

Acest exercițiu face parte din cursul

Vizualizarea datelor de tip serie temporală în Python

Vezi cursul

Instrucțiuni pentru exercițiu

Examinează meat_mean în shell -- un DataFrame care conține media tuturor seriilor de timp din meat.

  • Atribuie toate valorile din meat_mean argumentului cellText.
  • Atribuie toate valorile din indexul lui meat_mean argumentului rowLabels.
  • Atribuie numele coloanelor din meat_mean argumentului colLabels.

Exercițiu interactiv practic

Încearcă acest exercițiu completând acest cod de exemplu.

# Plot the meat data
ax = meat.plot(fontsize=6, linewidth=1)

# Add x-axis labels
ax.set_xlabel('Date', fontsize=6)

# Add summary table information to the plot
ax.table(cellText=meat_mean.____,
         colWidths = [0.15]*len(meat_mean.columns),
         rowLabels=meat_mean.____,
         colLabels=meat_mean.____,
         loc='top')

# Specify the fontsize and location of your legend
ax.legend(loc='upper center', bbox_to_anchor=(0.5, 0.95), ncol=3, fontsize=6)

# Show plot
plt.show()
Editează și rulează codul