0

I have a dataset with 1915 rows, that has an entry date col and a qty col contained in it. i.e.

10/22/2018 qty:1 10/22/2018 qty:3 11/22/2017 qty:1

Is it possible to edit the code below to multiply the count of dates by the qty associated with it? I've been fiddling around with where to put the multiplier but am stumped. This is the code I have running so far (without multiplier).

import pandas as pd
import matplotlib.pyplot as plt; plt.rcdefaults()
import matplotlib.dates as mdates
import numpy as np
import matplotlib.pyplot as plt

quotes = pd.read_csv("PO25474.csv")


quotes["ENTRY_DATE"] = quotes["ENTRY_DATE"].astype("datetime64")

plt.figure(figsize=(20, 10))

ax = (quotes["ENTRY_DATE"].groupby([quotes["ENTRY_DATE"].dt.year,\ 
quotes["ENTRY_DATE"].dt.month]).count().plot(kind="bar"))
ax.set_xlabel("quotes by month")
ax.set_ylabel("count")
ax.set_title("title")
plt.show()
Jack Kenny
  • 11
  • 4
  • I'm not sure I understand what you are trying to do. Something like [this](https://stackoverflow.com/a/39923012/3519000)? – lrnzcig Oct 17 '18 at 11:10
  • I hope to generate a bar chart that groups by the respective months but also takes into account the quantity associated on each line. At the moment it only counts each line by date but some lines have multiple quantities that I wish to include in the count. I'll try adding the sum function like the link you attached. – Jack Kenny Oct 17 '18 at 11:23

1 Answers1

0

I solved it. Had to put in QTY after the groupby and swap out count with sum.

import pandas as pd
import matplotlib.pyplot as plt; plt.rcdefaults()
import matplotlib.dates as mdates
import numpy as np

quotes = pd.read_csv("PO25474.csv")
qty = quotes[["ENTRY_DATE" , "QTY"]]

quotes["ENTRY_DATE"] = quotes["ENTRY_DATE"].astype("datetime64")

plt.figure(figsize=(12, 5))

ax = (quotes.groupby([quotes["ENTRY_DATE"].dt.year, quotes["ENTRY_DATE"].dt.month]) 
['QTY'].sum().plot(kind="bar"))
ax.set_xlabel("quotes by month")
ax.set_ylabel("count")
ax.set_title("PO25474")
plt.show()
Jack Kenny
  • 11
  • 4