2
good morning.
The task is as follows, I am trying to make a 'a,b,c' curve of products per company. I have the following df as an example:
df = pd.DataFrame({"empresa":["HST", "HST", "HST", "HSC", "HSC","HSC","HSC"],
"produto":["prod1", "prod2", "prod3", "prod4", "prod5", "prod6", "prod7"],
"vl_total": [100,200,150,50,200,300,400]
})
To make the abc curve, you need to create a column with the accumulated sum of the total value per company, and get the following value (vl_acm):
df = pd.DataFrame({"empresa":["HST", "HST", "HST", "HSC", "HSC","HSC","HSC"],
"produto":["prod1", "prod2", "prod3", "prod4", "prod5", "prod6", "prod7"],
"vl_total": [100,200,150,50,200,300,400],
"vl_acm": [100,300,450,50,250,550,950]
})
In Excel it is very easy to do this by applying the function sum up and putting the values of the column 'company' as conditional, but in Python I could not find a way to do it.
Thanks in advance guys.
Alive, what defines '...trying to make a turn...'?? Analyze this post I did once. https://answall.com/questions/444139/erro-utilizando-matplotlib/444339#444339 is this what you need? Set the example of the result you expect to get and the code you’ve already done to achieve it.
– Ernesto Casanova
Hello Ernesno. I’m referring to the a,b,c curve of product value, is a widely used classification in logistics. This post is about graphics, I saw no relation with what I requested above. The result I hope to get is the 'vl_acm' column of the second dataframe I posted above. I made it manually to illustrate, what I’m trying to do is to generate a solution to calculate this column in Python. I didn’t post code because unfortunately I don’t even know where to start... thank you!
– Alvaro Baraldi
Okay, I’m no expert in logistics, so I couldn’t infer that from your question, it wasn’t clear to anyone who wasn’t an expert. However, I think you should try to make some code and then share if there are problems, just so you can learn
– Ernesto Casanova
Yeah, I’m doing my best. Unfortunately, with the knowledge I have today, the closest I could get was to create a column with the total accumulated value, using the code 'df['vl_acm'] = df['vl_total']. cumsum()', but this solution does not respect the 'company' column as a condition, as I need it to be done. Anyway, thanks for the comment.
– Alvaro Baraldi