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
Last revisionBoth sides next revision
matches_to_coplays [2023/02/24 16:51] – [problem description] adminmatches_to_coplays [2023/02/24 17:01] – [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
 +    * I got the answer from here. I just added some intermediate steps to understand what is going on behind the scenes.
 +    * The page shows some alternative solutions which are worth exploring.
 +    * The page also shows how to get adjacency matrix
 +    * It also shows how to visualize the result with some cool graphs produced by the networkx package.
  
matches_to_coplays.txt · Last modified: 2023/02/24 17:03 by admin