【发布时间】:2020-03-09 14:20:24
【问题描述】:
【问题讨论】:
-
发布一个可复制的最小可复制示例。按照指南here。
标签: python pandas matplotlib seaborn
【问题讨论】:
标签: python pandas matplotlib seaborn
第一个想法是由#Series.reset_index 创建3 columns DataFrame,由DataFrame.drop_duplicates 删除重复项并由DataFrame.pivot 重塑:
df = (temp_1.reset_index(name='count')
.drop_duplicates('release_year')
.pivot('release_year','genres','count'))
或者通过Index.get_level_values 用Index.duplicated 和boolean indexing 删除MultiIndex 中的重复项,通过Series.unstack 重塑并最后创建3 columns DataFrame:
df = (temp_1[~temp_1.index.get_level_values('release_year').duplicated()]
.unstack()
.reset_index(name='count'))
DataFrame.plot.bar的最后一张图:
df.plot.bar()
【讨论】: