I have three arrays as listed below:
users
— Contains the id of 50000 users ( all distinct )pusers
— Contains the id of users who own some posts (contains repeated id's also, that is, one user can own many posts) [ 50000 values]score
— Contains the score corresponding to each value in pusers.[ 50000 values]
Now I want to populate another array PScore
based on the following calculation. For each value of users
in pusers
, I need to fetch the corresponding score
and add it to the PScore
array in the index corresponding to the user
.
Example,
if users[5] = 23224
and pusers[6] = pusers[97] = 23224
then PScore[5] += score[6]+score[97]
Items of note:
score
is related topusers
(e.g.,pusers[5]
hasscore[5]
)PScore
is expected to be related tousers
(e.g., cumulative score ofusers[5]
isPscore[5]
)- The ultimate aim is to assign a cumulative score of posts to the user who owns it.
- The users who don't own any posts are assigned a
score
of 0.
Can anyone help me in doing this? I tried a lot but once I run my different trials, the output screen remains blank until I Ctrl+Z
and get out.
I went through all of the following posts but I couldn't use them effectively for my scenario.
- Compare values of two arrays in python
- how to compare two arrays in python?
- Checking if any elements in one list are in another
I am new to this forum and I'm a beginner in Python too. Any help is going to be really useful to me.
Additional Information
- I'm working on a small project using StackOverflow data.
- I'm using Orange tool and I'm in the process of learning the tool and python.
Ok I understand that something is wrong with my approach. So shouldn't I use lists for this scenario? Can anyone please tell me how I should proceed with this?
Sample of the data that i have arrived at is as shown below.
PUsers Score
-1 0
-1 0
-1 0
-1 0
-1 0
-1 0
-1 0
-1 0
-1 0
-1 0
-1 0
-1 0
-1 0
-1 0
-1 0
-1 0
-1 0
-1 0
-1 0
-1 0
-1 0
-1 0
13 0
77 1
77 4
77 3
77 0
77 2
77 2
77 3
102 2
105 0
108 2
108 2
117 2
Users
-1
1
2
3
4
5
8
9
10
11
13
16
17
19
20
22
23
24
25
26
27
29
30
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
48
49
50
All that I want is the total score associated with each user. Once again, the pusers list contains repetition while users list contains unique values. I need the total score associated with each user stored in such a way that, if I say PScore[6]
, it should refer to the total score associated with User[6]
.
Hope I answered the queries.
Thanks in advance.