I have two DataFrames, one looks something like this:
df1:
x y Counts
a b 1
a c 3
b c 2
c d 1
The other has both an index and columns — a list of unique values in the first two columns:
df2
a b c d
a
b
c
d
What I would like to do is populate a second DataFrame with the values from the first, given that the intersection of the column and index is the same row from the first DataFrame, for example:
a b c d
a 0 1 3 0
b 1 0 2 0
c 3 2 0 1
d 0 0 1 0
While I try to use two for loops with a double if-condition, it makes a block of the computer (provided that the real DataFrame contains more than 1000 lines).
The part of the code I'm trying to implement (and which makes the calculations seem to be too "heavy" for the computer to work):
for i in df2.index:
for j in df2.columns:
if (i==df1.x.any() and j==df1.y.any()):
df2.loc[i,j]=df1.Counts
, (.. DataFrame) , , .
- , . - .
, , igraph. DataFrame, , , igraph.
, python-igraph dataframe , numpy.
, , .
( ).