Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How do I transform a matrix into a vector?

I have this matrix that contains x number of products and feedback rankings of 5 different categories.
This matrix is represented in a Pandas DataFrame like this:

index Bad ratings Slightly bad ratings Neutral ratings Slightly good ratings Good ratings
product1 9 0 0 0 0
product2 0 2 2 2 0
product3 2 1 3 0 0
product4 1 1 1 1 1
product5 0 0 0 4 4

How do I transform a matrix such as this to show the overall rank of each product?
E.g. like this where 0 is the worst and 9 is the best:

index Overall ratings
product1 1
product2 3
product3 2
product4 3
product5 4

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

Something like this?

df['Bad ratings'] *= -2
df['Slightly bad ratings'] *= -1
df['Good ratings'] *= 2

df.set_index('index').sum(1).rank().sort_values()

Output:

index
product1     1.0
product3     2.0
product4     3.0
product2     4.0
product5     5.0
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading