Reputation: 71
What is the difference between matplotlib.pyplot.plot()
and pandas.DataFrame.plot()
?
We can plot using both but what is the measure difference between both?
How can i draw bar chart and group by some categorical variable?
Upvotes: 7
Views: 10223
Reputation: 991
Matplotlib's pyplot is the library that Pandas use in their plot function. Pandas' plot is only a convenient shortcut. For the bar chart question: I would suggest using Seaborn's barplot, using the desired category as hue. If you wish to only use Pandas, then maybe something like:
df = pd.DataFrame(np.random.rand(10, 1), columns=['col_name'])
df['category'] = df.col_name>0.5
print(df)
col_name category
0 0.053908 False
1 0.136295 False
2 0.325790 False
3 0.362942 False
4 0.919924 True
5 0.406884 False
6 0.433959 False
7 0.725699 True
8 0.582537 True
9 0.608040 True
df.groupby('category').count().plot(kind='bar', legend=False)
Upvotes: 6