Pandas Seaborn绘图-沿轴添加频率

Pandas Seaborn绘图-沿轴添加频率,pandas,matplotlib,seaborn,Pandas,Matplotlib,Seaborn,对比目标变量绘制特征细节 # Read the data data=pd.read_csv("https://raw.githubusercontent.com/sharmaroshan/Online-Shoppers-Purchasing-Intention/master/online_shoppers_intention.csv") data.head() 参考目标变量的正常区域绘图: sns.countplot(x='Region',hue='Revenue',data=data)

对比目标变量绘制特征细节

# Read the data
data=pd.read_csv("https://raw.githubusercontent.com/sharmaroshan/Online-Shoppers-Purchasing-Intention/master/online_shoppers_intention.csv")
data.head()
参考目标变量的正常区域绘图:

sns.countplot(x='Region',hue='Revenue',data=data)

请帮助我获得沿绘图X轴的频率表:

(参考下图):

我找不到一个有“seaborn”字样的桌子。我添加了一个带有“matplotlib”的表来创建图形

df = data.loc[:,['Revenue','Region']]
df2 = df.groupby(['Revenue','Region'])['Revenue'].agg('count').to_frame('Count')
df2.reset_index(inplace=True)
df3 = df2.pivot(values='Count', columns='Region', index='Revenue')
df3 = df3.rename_axis(columns=None).reset_index()
df3.set_index('Revenue',inplace=True)
df3
        1   2   3   4   5   6   7   8   9
Revenue                                 
False   4009 948 2054 1007 266 693 642 378 425
True    771  188  349 175  52  112 119 56 86

import matplotlib.pyplot as plt

fig = plt.figure(figsize=(4,3),dpi=144)
ax = fig.add_subplot(111)

n_rows = len(df3)
labels = df3.columns.values
width = 0.35

x = np.arange(len(labels))
y1 = df3.iloc[0]
y2 = df3.iloc[1]

ax.bar(x - width/2, y1, width, label='False')
ax.bar(x + width/2, y2, width, label='True')
ax.set_xticks([])
ax.set_xticklabels([])

ax.legend()
cell_text = [list(y1.values),list(y2.values)]

ax.table(cellText=cell_text, rowLabels=df3.index, colLabels=df3.columns, loc='bottom')

plt.title('Region wise session vs Revenue Generated')
plt.ylabel('Count')
ax.set_xlabel('Region')
ax.xaxis.set_label_coords(0.5, -0.25)

plt.show()

你所说的频率是什么意思..你能详细说明一些样品吗。。我认为你必须改进csv的结构,否则我们欢迎你举个例子。我建议你展示你的完整代码..嗨,我附上了CSV(原始文件)作为数据,它是两个特性之间的双变量分析--地区和收入。使用计数图,我可以得到一般的格式。以便以表格的形式(在参考图像中)获得计数。请求一个可能重复的代码。@Quang Hoang,谢谢,但我认为这与Alpha有关。这是否回答了您的问题?