数据帧
Year Shows_Released ShowType
2018 13 tvSpecial
2018 14 Short
2018 8 movie
2019 9 tvSpecial
2019 11 Short
2018 10 Documentary
2019 11 movie
2018 6 Docudrama
2019 10 Documentary
2018 7 Drama
2019 14 Docudrama
我需要创建箱线图,显示 2018 年发布的 Shows_Released 与 2019 年发布的 Shows_Released
代码:
import pandas as pd
import matplotlib.pyplot as plt
df=pd.read_csv('filename')
df=df[['Year', 'Shows_Released']]
grouped_df=merge.groupby('Year')
for key, item in grouped_df:
print(grouped_df.get_group(key), "\n\n")
无法弄清楚如何使用所有值创建列表并将其传递给 plt.boxplot()
答案 0 :(得分:0)
这应该只使用 matplotlib:
import pandas as pd
import matplotlib.pyplot as plt
df=pd.read_csv('data.csv')
df = df[['Year', 'Shows_Released']].groupby("Year").sum().reset_index()
plt.bar(df.Year, df.Shows_Released,tick_label=df.Year )
plt.savefig("test")
请注意,我使用了条形图而不是箱形图,因为鉴于您的数据,箱形图没有任何意义,尤其是如果您只想汇总所有显示类型。