I have the following dataframe in pandas df_res, we can call it with a few rows as shown.
date time weekday team recipient
2019-08-30 14:49:22 Friday team1 [email protected]
2019-08-30 05:57:51 Friday team1 notification@listcom
2019-08-29 22:54:58 Thursday team1 [email protected]
2019-08-29 22:54:58 Thursday team1 [email protected]
2019-08-30 06:26:12 Friday team1 [email protected]
2019-09-05 14:16:22 Thursday team1 [email protected]
2019-09-05 14:16:22 Thursday team1 [email protected]
2019-09-04 22:54:59 Wednesday team1 [email protected]
2019-09-04 22:54:59 Wednesday team1 [email protected]
I want to plot a chart where the x-axis is a date ranging from June 2019 to Oct 2019. The y-axis is the count of how many times a recipient got an email in a given date. So I would like to do a stacked bar chart where each stack will be a recipient. For ex: on the date '2019-08-30', there are 2 mails for '[email protected]' and 1 for 'notification@listcom'. So I will have two stacks for that day. I also want to be able to provide a list of a few recipients whose email counts I am interested in. I wrote the below code to do the same but I'm struggling with how to get a count of the number of recipients. Instead if the count is a list or column, I am able to plot but that is not useful for me as the dataframe is huge with over a thousand rows.
import plotly.graph_objects as go
import datetime
x = [datetime.datetime(year=2019, month=06, day=4),
datetime.datetime(year=2019, month=11, day=5),
datetime.datetime(year=2019, month=13, day=6)]
y = [2, 2, 5]
fig = go.Figure(data=[go.Bar(x=x, y=y)])
# Use datetime objects to set xaxis range
fig.update_layout(xaxis_range=[datetime.datetime(2019, 06, 17),
datetime.datetime(2019, 10, 7)])
fig.show()
UPDATED TO ADD CODE: 10/11/2019 # plotting the values
trace = go.Bar(
x=[datetime.datetime(year=2019, month=8, day=1),
datetime.datetime(year=2019, month=10, day=1)],
y=[res_test['recipients'].value_counts()],
name='Plot the values '
)
data = [trace]
layout = go.Layout(title="Emails per volunteer", xaxis=
{'title':'Date'}, yaxis={'title':'Email count'},
barmode='stack'
)
fig = go.Figure(data=data, layout=layout)
py.iplot(fig)
Is this how I pass the value to the y-axis?