BaşlayınÜcretsiz Başlayın

Univariate plots in pandas

You'll start this chapter by using the plotting methods in pandas. This is typically done by calling the .plot() method on the relevant column, and passing in a value for the kind argument.

Histograms and boxplots are good for continuous data.

# Histogram
df['column_name'].plot(kind='hist')
plt.show()

# Boxplot
df['column_name'].plot(kind='box')
plt.show()

Bar graphs are good for categorical data. Remember to first obtain the counts of values using the .value_counts() method before plotting.

# Bar plot
counts = df['column_name'].value_counts()
counts.plot(kind='bar')
plt.show()

Remember to use the show() function from matplotlib.pyplot to display the plot.

Bu egzersiz

Python for R Users

kursunun bir parçasıdır
Kursu Görüntüle

Uygulamalı interaktif egzersiz

Bu örnek kodu tamamlayarak bu egzersizi bitirin.

import matplotlib.pyplot as plt

# Histogram of tip
tips.____.____(____)
____
Kodu Düzenle ve Çalıştır