0

I am trying to show user articles based on his user activity.

My user activity table has 3 columns ID,Category,Name So basically once a user read/click article these "three" fields updates based on which category of article he selected

Now based on his user activity i would like to show 10 articles from articles table based on which category of article he selected most for example

Category   # of articles read   
Sports           7
Weather          3

So the recommendation page should select 7 articles from sports category and 3 articles from weather category

Here is the code i have done so far

#Reading Articles from CSV
articles = pd.read_csv('articles.csv')

#User Activity Data
data = pd.read_csv('atc.csv',nrows=2000)

data1=data.rename(columns={'Category ':'Category'})
user_ac = data1[data1.Name=="Roxana"]

# number of articles read by 'Roxana' for each category
calc = user_ac.groupby('Category').count()['ID ']


#Sorting
sorted = calc.sort_values(ascending=False)

#Find probability for each category
b = user_ac.groupby('Category').count().div(len(user_ac))['ID ']
b=b.sort_values(ascending=False)

n_recommendation = 10 

How can i achieve this using pandas ?

GDRIVE LINK OF USER ACTIVITY https://drive.google.com/file/d/1d6rG0TE3dGYuU41AfTwn5T7dyoDniElY/view?usp=sharing

GDRIVE LINK OF Articles Data https://drive.google.com/file/d/15cK4p9vonmNNRZ_C5d26ULRivx6zSkrE/view?usp=sharing

eyllanesc
  • 235,170
  • 19
  • 170
  • 241
carl
  • 77
  • 1
  • 11
  • 1
    [Provide a copy of the DataFrame](https://stackoverflow.com/questions/52413246/how-do-i-provide-a-reproducible-copy-of-my-existing-dataframe) – Trenton McKinney Aug 24 '19 at 22:06
  • Please see my edits , I have included dataframes. – carl Aug 25 '19 at 07:47
  • Sorry i have uploaded wrong file , Now i have replaced with CSV File called Articles which have articles data – carl Aug 25 '19 at 08:04
  • The question states, the recommender suggests 7 sport and 3 weather articles. This doesn't correspond to the user `Roxana` in the code; she has read no weather related articles. The code aggregates some data and calculates the ratio or Categories for the user. Based upon the example, it's not possible to determine how you want to make a recommendation. – Trenton McKinney Aug 25 '19 at 08:53
  • I didn't drill into your data but probably you can: 1) shuffle your article dataframe 2) add a new column, assign incremental number group by type 3) select row where (type == 'sport' and num < 7) & (type == 'weather' and num < 3) – Louis Ng Aug 25 '19 at 09:00
  • 1
    Building a recommendation engine is a very broad topic. [Comprehensive Guide to build a Recommendation Engine from scratch (in Python)](https://www.analyticsvidhya.com/blog/2018/06/comprehensive-guide-recommendation-engine-python/) – Trenton McKinney Aug 25 '19 at 09:00
  • Basically I want to recommend X user articles based on what percentage of article category he read , so if a user has read 70 % of sports articles he should be shown most of articles related to sports category – carl Aug 25 '19 at 09:20

0 Answers0