Create a Stem and Leaf Plot in Python

Your goal

You need to create a stem and leaf plot in Python.

Step-by-step tutorial

To create a stem and leaf plot, you'll need the stemgraphic package:

$ pip install stemgraphic

Now let's load some data into a Pandas DataFrame:

>>> import pandas as pd
>>> precip = pd.read_csv('precip-central-park.csv')
>>> precip.head()
   YEAR   JAN   FEB   MAR   APR   MAY   JUN   JUL   AUG   SEP   OCT   NOV   DEC  ANNUAL
0  1869  2.53  6.87  4.61  1.39  4.15  4.40  3.20  1.76  2.81  6.48  2.03  5.02   45.25
1  1870  4.41  2.83  3.33  5.11  1.83  2.82  3.76  3.07  2.52  4.97  2.42  2.18   39.25
2  1871  2.07  2.72  5.54  3.03  4.04  7.05  5.57  5.60  2.34  7.50  3.56  2.24   51.26
3  1872  1.88  1.29  3.74  2.29  2.68  2.93  7.83  6.29  2.95  3.35  4.08  3.18   42.49
4  1873  5.34  3.80  2.09  4.16  3.69  1.28  4.61  9.56  3.14  2.73  4.63  2.96   47.99

Now let's generate a stem and leaf plot for March:

>>> import stemgraphic
>>> stemgraphic.stem_graphic(precip['MAR'])
(<Figure size 750x625 with 1 Axes>, <matplotlib.axes._axes.Axes object at 0x141820640>)
>>> fig, ax = stemgraphic.stem_graphic(precip['MAR'])
>>> fig.show()
March precipitation in Central Park, 1869-2019
March precipitation in Central Park, 1869-2019