1

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
2
  • Can you add some data and what you are trying to plot? You can get Seaborn style while using pandas plot by import seaborn as sns then using sns.set(). Commented Apr 1, 2019 at 13:18
  • I have added the sample data. Commented Apr 1, 2019 at 13:41

2 Answers 2

3

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()

showing the resulting graph

Sign up to request clarification or add additional context in comments.

Comments

1

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()

output after value_counts()

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")

Graph of value counts

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.