[英]Networkx TypeError: Input graph is not a networkx graph type
我正在嘗試使用from_pandas_edgelist
創建有向圖。 傳遞參數create_using=nx.DiGraph()
出現錯誤
1)我嘗試創建一個有向圖對象,然后嘗試使用from_pandas_edgelist
創建一個圖:但它將所有鏈接創建為雙向
G=nx.DiGraph() G=nx.from_pandas_edgelist(df_SearchRelations,source='ParentCompanyId',target='ChildCompanyId',edge_attr=True)
2)我嘗試創建一個圖形對象,然后使用to_directed()
進行轉換,但沒有運氣
G=nx.from_pandas_edgelist(df_SearchRelations,source='From',target='To',edge_attr=True)
G=G.to_directed()
預期結果:克服TypeError: Input graph is not a networkx graph type
PS:同樣的代碼曾經可以工作,但突然失敗了。 我不確定這是版本兼容性問題還是數據框問題。
嘗試使用create_using
參數:
G = nx.from_pandas_edgelist(df_SearchRelations,
source='ParentCompanyId',
target='ChildCompanyId',
edge_attr=True,
create_using=nx.DiGraph())
我發現當圖中的每個節點都沒有連接時,有向圖生成器會出錯。 所以當我們將 edge_list 作為 pandas 數據幀傳遞時,我們應該檢查是否有任何斷開的子圖/節點。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.