January 28, 2020

  1. Start a python program that will use Pandas and Matplotlib

    1. from matplotlib import pyplot as plt

    2. import pandas as pd

  2. Read a csv file and set it as data to be plotted

    1. orders = pd.read_csv(‘orders.csv’)

  3. Take the date column and use the month to create a new df

    1. orders[‘math’] = orders.date.apply(lambda x: x.split(‘-’)[0])

    2. This takes the first values before the ‘-’ in the date and makes a new column

  4. Get the average order by month and save it to a variable

    1. avg_order = orders.date.groupby(‘month’).price.mean( ).reset_index( )

  5. Get the standard deviation for the orders by month and save it to a variable

    1. std_order = orders.date.groupby(‘month’).price.mean( ).reset_index( )

  6. Create a set of axes using plt.subplot and save them to a variable

    1. ax = plt.subplot( )

  7. Create a variable with the average prices in it by selecting the column price from avg_order. Save this to bar_heights

    1. bar_heights = avg_order.price

  8. Create a variable with the standard deviation of prices in it by selecting the column price for std_order. Save this to bar_errors.

    1. bar_errors = std_order.price

  9. Create a bar chart to share this data. The height of each bar should come from bar heights. Use the standard deviations in bar_errors as the yerr. The error capsize should be 5. Label each bar with the name of the month. Label the y axis. Give the plot a descriptive title.

    1. plt.bar(range(len(bar_heights)), bar_heights, yerr=bar_errors, capsize = 5)

    2. ax.set_xticks(range(len(bar_heights)))

    3. ax.set_xticklabels([‘April’, ‘May’, ‘June’, ‘July’, ‘August’, ‘September’])

    4. plt.ylabel(‘Average Order Amount’)

    5. plt.title(‘Order Amount over Time’)

    6. plt.show( )

Previous
Previous

January 29, 2020

Next
Next

January 9, 2020