I have a large dataset, df:
User duration
amy 582
amy 27
amy 592
amy 16
amy 250
tom 33
tom 10
tom 40
tom 100
I would like to group by User, and then create a histogram for each User:
amy (histogram image)
tom (histogram image)
Here is the dput:
structure(list(User = structure(c(1L, 1L, 1L, 1L, 1L, 2L, 2L,
2L, 2L), .Label = c("amy", "tom"), class = "factor"), duration = c(582L,
27L, 592L, 16L, 250L, 33L, 10L, 40L, 100L)), class = "data.frame", row.names = c(NA,
-9L))
I know how to create a histogram in Python using the following code:, but how do I create multiple histograms in python, grouping by the User. Should I create a dictionary?
import numpy as np
import matplotlib.mlab as mlab
import matplotlib.pyplot as plt
df = (amy[582,27, 592, 16, 250], tom[33,10,40,100])
num_bins = 20
n, bins, patches = plt.hist(x, num_bins, facecolor='blue', alpha=0.5)
plt.show()
Any suggestion is appreciated.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.