I need to reorganize the values for 2 categories so that I can make ratios that I then use for a histogram.
ld_mn = []
for ld in ldprs:
nmrtr = []
for ty in types:
nmrtr.append(min(lps.loc[(lps['num'] == ld) & (lps['let_typ'] == ty) & (lps['num_typ'] == 'BUSINESS RULES')],
lps.loc[(lps['num'] == ld) & (lps['let_typ'] == ty) & (lps['num_typ'] == 'BUSINESS RULES')]))
nmrtr.append(max(sum(nmrtr),1))
print(nmrtr,ld)
for i in range(len(nmrtr)):
ld_mn.append(nmrtr[i]/ld_vl[ld])
nmrtr is meant to be the numerator of a calculation where the sum of the values in the row are then divided by value counts of the 'num' from the original data. Sum(min(typ_1, typ_2)/sum(all types) is the intended calculation. I'm getting errors when I run the code. Syntax error on the 7th line beginning with nmrtr and ValueError: The truth value of a DataFrame is ambiguous. Use a.empty, a.bool(), a.item(), a.any() or a.all() on line 5 beginning with nmrtr. I was going to later turn these iterations into a data frame if needed.
fake data to play with:
[121, der, cat, dog]
[131, mnd, cat, dog]
[141, der, cat, dog]
Both How I'd like the table to be to make it easier to not force the calculation
|num |let_type|cat | dog
|121 | der | 7 | 12
|131 | mgh| 7 | 12
|141 | plm | 7 | 12
cat and dog are categories, but I'd like the new df to count the frequency. num is a unique identifier. let_type is whats being counted. it is a subcategory for car and dog. let_type will end up being a unique value within each num.