我正在尝试使用matplotlib / seaborn可视化熊猫系列的另一种方法。但是我做不到。有什么办法吗?
使用熊猫的df.plot()方法可视化它没有问题。
df2.groupby('Company').Company.count()
数据如下:
100 a
101 b
102 c
103 d
104 a
105 c
106 d
107 b
108 a
109 c
答案 0 :(得分:3)
您可以使用seaborn的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()
答案 1 :(得分:1)
在@Orysza给出的答案之外,如果要对系列进行排序进行绘图,则可以使用系列的内置方法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")