Reputation: 1946
How do I generate a pyplot line chart from the following groupby
where the y values
represent the counts for each 'enabled_flag' value?
df = pd.DataFrame({'date': ['2019-10-06', '2019-10-06','2019-10-06', '2019-10-07', '2019-10-07'],
'enabled_flag': ['y', 'y','n', 'y', 'n']})
df.groupby(['date','enabled_flag'])['enabled_flag'].count()
So, the x-axis is 'date' and y has two axis, one for the 'Y' counts and the other for the 'N' counts.
Upvotes: 0
Views: 31
Reputation: 150735
You could do:
(df.groupby(['date','enabled_flag'])['enabled_flag'].count()
.unstack()
.plot()
)
Or
(df.groupby('date')['enabled_flag'].value_counts()
.unstack()
.plot()
)
Output:
Upvotes: 1
Reputation: 86
plt.gca().set_color_cycle(['green', 'yellow'])
for dtype in ['Y', 'N']:
plt.plot(
'Datetime',
dtype,
data=df,
label=dtype,
alpha=0.8
)
plt.legend()
plt.grid()
plt.show()
Try this. Does this work ?
Upvotes: 0