Удаление группы по итогу и создание гистограммы из результатов - PullRequest
0 голосов
/ 04 июня 2019

Мне нужно создать гистограмму из групп данных. Мне нужны только группы с более высокими показателями на графике. Могу ли я получить помощь в изменении групп и составлении гистограммы.

Я могу найти группы, которые нужно удалить, и я могу создать столбцы на основе группировок.

import matplotlib.pyplot as plt
import pandas as pd

#csv holds 3 columns App Name, Region Number, District Number (if applicable), # regs holds unique region numbers, apps holds unique app names
fig= plt.figure(figsize=(9,6))
d = pd.read_csv('xxx/licenses.csv')
regs = d.Region.unique()
apps = d.AppName.unique()

#df3 will end up holding the correct list of app names. I only want to chart
# the apps that have over 5 total.
df = d.groupby(['AppName']).size().reset_index(name='counts')
df2  = df['counts'] > 5
df3=df[df2]

#This appropriately groups and graphs the groupings, but includes all 
# applications, not the the ones with totals > 5
counts = d.groupby(['AppName','Region']).count()
totals = counts.sum(level=0)
counts = counts.unstack(level=1)
counts.columns = counts.columns.droplevel(level=0)
counts = counts.fillna(0)

#all bars are on top of each other. need to calculate the bottom for each 
# iteration. 
# x axis should have app names, y should be count of districts in region, 
# with each region its own color to see which regions are using which app
for reg in regs:
    plt.bar(apps, counts[reg], bottom=None)
plt.show()

Бары накладываются друг на друга, но все начинаются с 0. Они должны начинаться с максимума предыдущего.

Только диаграммы с итогами> 5 должны быть намечены

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...