簡體   English   中英

igraph未在Python中將屬性寫入graphml

[英]igraph not writing attribute to graphml in Python

我有一個igraph圖形對象g ,具有以下屬性列表:

IN: g.vertex_attributes()
OUT: ['Label',  'mentioned',  'retweeted',  'community_id']

然后,我嘗試從現有的熊貓數據框中創建一個新屬性,如下所示:

IN: g.vs['profile_status'] = y['profile_status']

... y看起來像這樣:

IN: y.head()
OUT:   user.screen_name    profile_status
0   username1   User profile active
1   username2   User profile active
2   username3   Account deleted or suspended
3   username4   User profile active
4   username5   User profile active

...結果是現在看起來像這樣的屬性列表,並添加了新屬性:

IN: g.vertex_attributes()
OUT: ['Label',  'mentioned',  'retweeted',  'community_id', 'profile_status']

但是,運行此命令時, profile_status字段未寫入到graphml文件中:

IN: g.write_graphmlz(NETWORK_OUTPATH)

在文本編輯器中打開graphml文件顯示任何地方都沒有profile_status字段。

有什么想法我做錯了嗎? 謝謝!

igraph似乎在處理字符串屬性時遇到麻煩,因此將字符串值轉換為整數代碼可以解決問題。 這是我的操作方式:

# Generate list of statuses and their integer codes
possible_statuses = {y:x for x,y in enumerate(y['profile_status'].unique())}
print(possible_statuses)
y['profile_status_code'] = y['profile_status'].apply(lambda x: possible_statuses[x])

g.vs['profile_status_code'] = y['profile_status_code']

# Write network to file
g.write_graphmlz(NETWORK_OUTPATH)

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM