我有一个包含点击次数和展示次数的数据集,我使用groupby和agg将它们汇总到星期几
df2=df.groupby('day_of_week',as_index=False, sort=True, group_keys=True).agg({'Clicks':'sum','Impressions':'sum'})
然后我试图用子图
绘制它们f, axes = plt.subplots(2, 2, figsize=(7, 7))
sns.countplot(data=df2['Clicks'], x=df2['day_of_week'],ax=axes[0, 0])
sns.countplot(data=df2["Impressions"], x=df2['day_of_week'],ax=axes[0, 1])
但是使用星期几作为X,情节使用了点击次数和展示次数中的值。有没有办法强制X到星期几,而值是在Y?感谢。
完整代码
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
import seaborn as sns
sns.set_style("whitegrid")
df=pd.read_csv('data/data_clean.csv')
df2=df.groupby('day_of_week',as_index=False, sort=True, group_keys=True).agg({'Clicks':'sum','Impressions':'sum'})
f, axes = plt.subplots(2, 2, figsize=(7, 7))
sns.countplot(data=df2['Clicks'], x=df2['day_of_week'],ax=axes[0, 0])
sns.countplot(data=df2["Impressions"], x=df2['day_of_week'],ax=axes[0, 1])
plt.show()
假数据:
day_of_week,Clicks,Impressions
0 100 2000
1 400 4000
2 300 3500
3 200 2000
4 100 1000
5 50 500
6 10 150