Код: Выделить всё
import pandas as pd
import networkx as nx
# Read input
df = pd.read_csv("org.csv")
# Create the input adjacency matrix
am = pd.DataFrame(0, columns=df["Worker"], index=df["Worker"])
# This way, it is impossible that the dataframe is not square,
# or that index and columns don't match
# Fill the matrix
for ix, row in df.iterrows():
am.at[row["manager"], row["Worker"]] = 1
# At this point, am.shape returns a square dataframe (2825,2825)
# Generate the graph
G = nx.from_pandas_adjacency(am, create_using=nx.DiGraph)
И действительно, размеры, указанные в ошибке, не такие же, как во входном кадре данных am.
Есть ли у кого-нибудь представление о том, что происходит в from_pandas_adjacency, что может привести к этому несоответствие?
Подробнее здесь: https://stackoverflow.com/questions/794 ... h-networkx
Мобильная версия