[英]Create a bar graph with a DataFrame
I have a data frame that looks like this:我有一个看起来像这样的数据框:
Cursos Per1 Per2 Per3 Per4 ... Per46 Per47 Per48 Per49 Per50
0 Curso1 True False False False ... False False False True False
1 Curso2 False False False False ... False False False False False
Where the columns are gropued by 10 - ('Per1' to 'Per10') ('Per11' to 'Per20')... And each of these groups represents a day of the week - Monday, Tuesday etc.其中列按 10 进行分组 - ('Per1' 到 'Per10')('Per11' 到 'Per20')......并且这些组中的每一个都代表一周中的一天 - 星期一,星期二等。
I have to create a bar graphic with the values of every of these groups of 'days' where the value is 'True' (That means, there is class in that period in that day).我必须创建一个条形图,其中每个“天”组的值为“真”(这意味着,在那一天的那个时期有 class)。
In the end, there should be 5 bars (one per day) with the infomation regarding the amounts of "Per" that have values of 'True'.最后,应该有 5 个柱形图(每天一个柱形图),其中包含关于值为“True”的“Per”数量的信息。
This proyect is already 4,746 lines long, and this is the final step, I would greatly appreciate any help!这个项目已经有 4,746 行了,这是最后一步,我将非常感谢任何帮助!
Example of the graphic:图形示例:
Where the days are at the bottom (they are in spanish in this case, and the number of periods with 'true' values are at the left.日期在底部(在这种情况下它们是西班牙语,具有“真实”值的时段数在左侧。
You can use groupby()
along the columns to sum:您可以沿列使用groupby()
来求和:
(df.set_index('Cursos')
.groupby(np.arange(50)//10, axis=1)
.sum().T.plot.bar()
)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.