My dataframe looks like this:
date id pct_change
12355258 2010-07-28 60059 0.210210
12355265 2010-07-28 60060 0.592000
12355282 2010-07-29 60059 0.300273
12355307 2010-07-29 60060 0.481982
12355330 2010-07-28 60076 0.400729
I would like to write it with the columns 'target', 'source', 'weights', where: 'target' and 'source' are both 'id's, and 'weights' counts on how many days both the 'target' and 'source' changed price simultaneously. So it would look like:
target source weights
60059 60060 2
60059 60076 1
60060 60076 1
My goal is to use this dataframe to make a networkx graph.
I have tried using groupby
df.groupby(['date','id'])['id'].unique().value_counts()
df.groupby(['date','id'])['id'].count()
and for loops (which were terrible).
I feel like I am missing a small step in the groupby, but couldn't tell what was missing.
Thank you for your help.