How to use groupby while plotting the graph?

I have a dataset which I used groupby operation to count and group data. it would be like this:
df=data.groupby(data.col1)[‘col2’].count()
plt.bar(df.col1, col2, data=df)
it keeps giving errors. If I do it this way,
data.groupby(data.col1)[‘col2’].count().plot.bar()
it would plot what I want. So what am I missing here?