python - Pandas calculate number of values between each range -
i want find counts of data between custom ranges.
say have data:
import random my_randoms = random.sample(xrange(100), 10) test = pd.dataframe(my_randoms,columns = ["x"]) how can produce data frame shows number of values between different ranges? example, want see how many values occur between 0-19, 20-39, 40-59, 60-79, 80-100. output dataframe have 1 column ranges, counts.
i can think of ugly approaches involve use of .apply new column list saying value between (and doing groupby), suspect pandas has cleaner way lurking about.
per jarad's link other question:
test.groupby(pd.cut(test['x'], np.arange(0,100,20))).count()
Comments
Post a Comment