Я взял образец из 20 фильмов, чтобы продемонстрировать, как это сделать. Ядро qcut . Вы также можете использовать cut , если хотите определить свои собственные сегменты. Для этого примера я выбрал 3 ведра, а не 2, как указано. Ясно, что изменение на 2 - это просто изменение параметров на qcut()
dfa = pd.DataFrame({'ImdbId': ['tt8579674', 'tt7329656', 'tt7608418', 'tt10006006', 'tt8709036', 'tt2112096', 'tt0445922', 'tt2316204', 'tt0437086', 'tt6189022', 'tt7456310', 'tt0478970', 'tt4154796', 'tt1727824', 'tt6857166', 'tt6823368', 'tt0452625', 'tt3896198', 'tt1846589', 'tt5580036', 'tt4058368'],
'Title': ['1917', '47 Meters Down: Uncaged', 'A Christmas Prince', 'A Christmas Prince: The Royal Baby', 'A Christmas Prince: The Royal Wedding', 'Absolutely Fabulous: The Movie', 'Across the Universe', 'Alien: Covenant', 'Alita: Battle Angel', 'Angel Has Fallen', 'Anna', 'Ant-Man', 'Avengers: Endgame', 'Bohemian Rhapsody', 'Book Club', 'Glass', 'Good Luck Chuck', 'Guardians of the Galaxy Vol. 2', 'Hunter Killer', 'I, Tonya', 'If There Be Thorns'],
'Runtime': [119, 90, 92, 84, 92, 91, 133, 122, 122, 122, 119, 117, 181, 135, 104, 129, 101, 137, 122, 120, 100]})
# do buckets as ranges and as names
dfa["bucket"] = pd.qcut(dfa["Runtime"], 3)
dfa["named_bucket"] = pd.qcut(dfa["Runtime"], 3, labels=["short","medium","long"])
# generate plots with sensible limits on min/max
dfa.groupby("named_bucket").mean().plot(kind="barh",
xlim=(dfa["Runtime"].min(),dfa["Runtime"].quantile(0.97)))
dfa.groupby("bucket").mean().plot(kind="barh",
xlim=(dfa["Runtime"].min(),dfa["Runtime"].quantile(0.97)))
введите описание изображения здесь