0

A small snipet of my dataframe is given below.

       UserID                Recommendations
 0      A001        [(B000OR5928, 5.671419620513916), (B000A1HU1G, 5.435572624206543), (B0039HBNMA, 5.4260640144348145), (B000EEGAJW, 5.502416133880615), (B001L8KE06, 5.508320331573486), (B0002ZO60I, 5.640686511993408), (B0002D0096, 5.543562412261963), (B0013PU75Y, 5.452023506164551), (B005M0TKL8, 5.481754302978516), (B001PGXHYO, 5.5017194747924805)]
 1      A002        [(B000EEGAJW, 4.382242679595947), (B004ZKIHVU, 4.182255268096924), (B000CBE3GE, 4.242227077484131), (B000CCJP4I, 4.354374408721924), (B000VBC5CY, 4.342846393585205), (B0002KZHQA, 4.127199649810791), (B0026RB0G8, 4.246310234069824), (B0002D0CQC, 4.275753021240234), (B0002M6CVC, 4.679849624633789), (B0002D0KOG, 4.138158321380615)]

The dataframe contains two columns UserID and Recommendations.The recommendation column contains productID of products recommended to that user along with ratings which is in the form of list.

What I want to do is if I click on user A001 then a graph should get display.The y-axis of graph will display productIDs recommended to A001 and X-axis will display rating of that product.This should be done in case of each UserID

I know how to plot a graph with single values using matplotlib but here it has a list of values .How can I go about it.

2
  • Please show some code! People will be more likely to help if you provide evidence that you've given it a good go. Commented Mar 15, 2019 at 13:29
  • 1
    Yes I am working on it.Soon I will edit it with some code as even I am not getting how to start. Commented Mar 15, 2019 at 13:41

1 Answer 1

1

You can try this code to solve your problem:

import matplotlib.pyplot as plt
import numpy as np

for i in df.UserID:
  ratings = []
  productsIDs = []

  for points in df.Recommendations[np.where(df.UserID==i)[0]]:
    for point in points:
      ratings.append(point[1])
      productsIDs.append(point[0])

    plt.plot(ratings, productsIDs)
    plt.show()
Sign up to request clarification or add additional context in comments.

3 Comments

Hey,Thanks for trying.But this is not working for me.
Not an error message but the graphs are not showing correct result.It is taking wrong scale for ratings and ProductID is not shown on y-axis.Even plotting is not showing up,just x and y axis.I am trying to sort it properly.
I edited my code, I made some mistakes with the x and y axis names, now it should works.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.