0

Apparently this question has already been answered, and I still cannot find a solution from the precedent material. I appoligize...

I am trying to add the index of the dataframe to a list after the if statement. I think the code is pretty explanatory. But, it is storing the values of the column instead of the value of the index.

here is my code:

what['revenueSKU'] = round(what['Quantity'] * what['Unit_cost'])
what['value(in%)'] = round(((what['revenueSKU']/t)*100),10)
classifier = pd.concat([what['value(in%)'],what['SKU']], axis=1, join='outer')
classifier1 = classifier.sort_values(by='value(in%)',ascending= False)
classifier1 = classifier1.set_index('SKU',drop=True,inplace=False)

print(classifier1)
cumulative_percentage = classifier1.cumsum()
print(cumulative_percentage)

classa = []
classb = []
classc = []
for sku in cumulative_percentage['value(in%)']:
    if sku < 80:
        classa.append(sku)

    elif 80 < sku <=90:
        classb.append(sku)
    else:
        classc.append(sku)

print('classa =', classa)
print('classb =', classb)
print('classc =', classc)

would someone have a hint of what needs to be changed?

also, i am a python beginner and i feel like everything I write is very unefficient, if someone also have advice on how I could improve on that, I would be so happy. Any help would be really appreciated.

Murcielago
  • 905
  • 1
  • 8
  • 30
  • Use `classa = cumulative_percentage[cumulative_percentage['value(in%)'] < 80]` – jezrael Oct 17 '19 at 06:23
  • thank you for the help, I didn't think of the problem in this way, and I would not have. thanks again – Murcielago Oct 17 '19 at 06:55
  • Hi. Please take the time to read this post on [how to provide a great pandas example](http://stackoverflow.com/questions/20109391/how-to-make-good-reproducible-pandas-examples) as well as how to provide a [minimal, complete, and verifiable example](http://stackoverflow.com/help/mcve) and revise your question accordingly. These tips on [how to ask a good question](http://stackoverflow.com/help/how-to-ask) may also be useful. – jezrael Oct 17 '19 at 06:55
  • thanks, I can for sure make use of that. – Murcielago Oct 17 '19 at 06:57

0 Answers0