首页 > 解决方案 > 处理networkx中的时间戳

问题描述

尝试GEXF从 networkx 写入文件时:

import pandas as pd
import networkx as nx

data  = pd.DataFrame({'src':[1,2], 'dst':[2,1], 'attr_1':['foo', 'bar'], 'time':[pd.Timestamp.now(), pd.Timestamp.now()]})
G = nx.from_pandas_edgelist(data, source='src',
                            target='dst',
                           edge_attr=['attr_1', 'time'],
                           create_using= nx.MultiGraph())
nx.write_gexf(G, "visualization.gexf")

错误:

attribute value type is not allowed: <class 'pandas._libs.tslibs.timestamps.Timestamp'>

可以观察到。除了字符串格式化networkx的时间戳之外没有其他方法来处理它吗?

标签: pythonpandastimestampnetworkx

解决方案


推荐阅读