[英]Plotting a Pandas series in Matplotlib/seaborn
I am trying an alternate way to visualize a pandas series using matplotlib/seaborn. 我正在尝试使用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. 我使用熊猫的df.plot()方法可视化它没有问题。
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
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
加上@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")
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.