User Tools

Site Tools


matches_to_coplays

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
matches_to_coplays [2023/02/24 16:51] – [problem description] adminmatches_to_coplays [2023/02/24 17:03] (current) – [Solution] admin
Line 104: Line 104:
 Groupby on player_id1, player_id2 and get the size of each group Groupby on player_id1, player_id2 and get the size of each group
 <code> <code>
-In [4]: +In [9]: 
-df.merge(df, on='match_id', how='inner', suffixes=('1', '2')).groupby(['player_id1', 'player_id2']).size() +df.merge(df, on='match_id', how='inner', suffixes=('1', '2'))
-Out[4]:+.groupby(['player_id1', 'player_id2'])
 +.size() 
 +Out[9]:
 player_id1  player_id2 player_id1  player_id2
 a                       2 a                       2
Line 117: Line 119:
             b             1             b             1
             c             2             c             2
 +dtype: int64
 </code> </code>
  
 We want player_id1 and player_id2 as columns instead of as index. We want player_id1 and player_id2 as columns instead of as index.
 <code> <code>
-In [5]: +In [11]: 
-df.merge(df, on='match_id', how='inner', suffixes=('1', '2')).groupby(['player_id1', 'player_id2'], as_index=False).si ze() +df.merge(df, on='match_id', how='inner', suffixes=('1', '2'))
-Out[5]:+.groupby(['player_id1', 'player_id2'], as_index=False)
 +.size() 
 +Out[11]:
   player_id1 player_id2  size   player_id1 player_id2  size
 0          a          a     2 0          a          a     2
Line 136: Line 141:
 </code> </code>
  
 +See also:
 +  * https://stackoverflow.com/questions/75537816/transform-a-dataframe-for-network-analysis-using-pandas
 +    * It is worth going through this page in its entirety.
 +    * I got the answer from here. I just added some intermediate steps to understand what is going on behind the scenes.
 +    * It shows some alternative solutions which are worth exploring.
 +    * It shows how to get the adjacency matrix
 +    * It also shows how to visualize the result with some cool graphs produced by the networkx package.
  
matches_to_coplays.1677257473.txt.gz · Last modified: 2023/02/24 16:51 by admin