Reputation: 75
I am trying an alternate way to visualize a pandas series using matplotlib/seaborn. But I am not able to do it. Is there any way?
I have no problem visualizing it using the df.plot() method of pandas.
df2.groupby('Company').Company.count()
Data looks like this:
100 a
101 b
102 c
103 d
104 a
105 c
106 d
107 b
108 a
109 c
Upvotes: 1
Views: 3430
Reputation: 111
Adding on to the answer given by @Orysza , in case you want the Series sorted for plotting, you could use the Series' in-built method value_counts
import seaborn as sns
import pandas as pd
import matplotlib.pyplot as plt
tmp = pd.DataFrame()
tmp["vals"] = ["a", "b", "c", "d", "a", "c", "d", "b", "a", "c"]
tmp_valc = tmp["vals"].value_counts()
tmp_valc.head()
f, ax = plt.subplots(1, 1, figsize=(5,5))
g = sns.barplot(x=tmp_valc.index, y=tmp_valc)
t = g.set(title="Value counts of Pandas Series")
Upvotes: 1
Reputation: 714
You could use seaborn's countplot
:
import matplotlib.pyplot as plt
import seaborn as sns
import pandas as pd
test = pd.DataFrame()
test["Company"] = ["a", "b", "c", "d", "a", "c", "d", "b", "a", "c"]
ax=sns.countplot(test["Company"])
plt.show()
Upvotes: 3