Reputation: 33
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.
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).
In the end, there should be 5 bars (one per day) with the infomation regarding the amounts of "Per" that have values of 'True'.
This proyect is already 4,746 lines long, and this is the final step, I would greatly appreciate any help!
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.
Upvotes: 0
Views: 62
Reputation: 153460
Try:
df.set_index('Cursos').groupby(np.arange(50)//10, axis=1)\
.sum().sum()\
.rename(index={n:i for n,i in enumerate(['lunes', 'martes', 'miercoles', 'jueve', 'viernes'])})\
.plot.bar()
Output:
Upvotes: 0
Reputation: 150735
You can use groupby()
along the columns to sum:
(df.set_index('Cursos')
.groupby(np.arange(50)//10, axis=1)
.sum().T.plot.bar()
)
Upvotes: 1