Plotting directly using pandas

Python for R Users

Daniel Chen

Instructor

Plotting in Python

  • Quickly show data patterns
  • Plotting methods in Python:
    • pandas
    • Seaborn
    • Matplotlib
Python for R Users

Pandas plot method

  • plot() method
  • Works on the pandas DataFrame and Series objects
  • Pass plot the kind argument
  • kind of plots:
    • line : line plot (default)
    • bar : vertical bar plot
    • barh : horizontal bar plot
  • hist : histogram
  • box : boxplot
  • kde : Kernel Density Estimation plot
  • density : same as ‘kde’
  • area : area plot
  • pie : pie plot
  • scatter : scatter plot
  • hexbin : hexbin plot
Python for R Users

Univariate: Histogram

import matplotlib.pyplot as plt
iris['sepal_length'].plot(kind='hist')
plt.show()

Python for R Users

Univariate: Bar plot

cts = iris['species'].value_counts()
cts.plot(kind='bar')
plt.show()

Python for R Users

Bivariate: Scatter plot

iris.plot(kind='scatter', x='Sepal.Length', y='Sepal.Width')
plt.show()

Python for R Users

Bivariate: Boxplots

iris.plot(kind='box')
plt.show()

Python for R Users

Bivariate: Boxplots

iris.boxplot(by='Species', column='Sepal.Length')
plt.show()

Python for R Users

Let's practice!

Python for R Users

Preparing Video For Download...