Add source example files
This commit is contained in:
12
source/pandas/02-charts/bar-chart.py
Normal file
12
source/pandas/02-charts/bar-chart.py
Normal file
@ -0,0 +1,12 @@
|
||||
import pandas as pd
|
||||
from matplotlib import pyplot
|
||||
from matplotlib.axes import Axes
|
||||
|
||||
df = pd.read_excel("sample-data-food-sales.xlsx", sheet_name="FoodSales")
|
||||
groups = df.groupby(["Region", "City"])
|
||||
averages = groups.mean(numeric_only=True)
|
||||
|
||||
axis: Axes = averages.plot.bar(rot=0)
|
||||
for p in axis.patches:
|
||||
axis.annotate(f"{p.get_height():.1f}", (p.get_x() + 0.05, p.get_height() + 5), rotation=90)
|
||||
pyplot.show()
|
Reference in New Issue
Block a user