本文整理汇总了Python中graph_tool.Graph.edge_properties[col]方法的典型用法代码示例。如果您正苦于以下问题:Python Graph.edge_properties[col]方法的具体用法?Python Graph.edge_properties[col]怎么用?Python Graph.edge_properties[col]使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类graph_tool.Graph
的用法示例。
在下文中一共展示了Graph.edge_properties[col]方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: graph_from_dataframes
# 需要导入模块: from graph_tool import Graph [as 别名]
# 或者: from graph_tool.Graph import edge_properties[col] [as 别名]
def graph_from_dataframes(vertex_df, edge_df):
'''Re-creates a Graph object with PropertyMaps taken
from the vertex_df and edge_df DataFrames
Paramters:
==========
verex_df: a DataFrame with an index named 'vertex_index'
edge_df: a DataFrame with a multi-index named ('source', 'target')
Returns:
========
graph: a grah-tool Graph with PropertyMaps copied
from the columns of the input DataFrames
'''
graph = Graph(directed=True)
vertex_index = vertex_df.index.get_level_values(level='vertex_index')
vertices = graph.add_vertex(n=vertex_index.shape[0])
for col in vertex_df.columns:
in_type = vertex_df[col].dtype.name
try:
dtype = ALIASES[in_type]
except KeyError:
log.info('Data type {} not supported'.format(in_type))
continue
prop = graph.new_vertex_property(dtype)
prop.fa = vertex_df[col]
graph.vertex_properties[col] = prop
src = edge_df.index.names.index('source')
trgt = edge_df.index.names.index('target')
### TODO: use the list edge creation
for tup in edge_df.index:
source, target = tup[src], tup[trgt]
try:
edge = graph.add_edge(source, target)
except ValueError:
log.info('Invalid vertex in (source: {}, target: {})'.format(source, target))
for col in edge_df.columns:
in_type = edge_df[col].dtype.name
try:
dtype = ALIASES[in_type]
except KeyError:
log.info('Data type {} not supported'.format(in_type))
continue
prop = graph.new_edge_property(dtype)
prop.fa = edge_df[col]
graph.edge_properties[col] = prop
return graph
示例2: graph_from_dataframes
# 需要导入模块: from graph_tool import Graph [as 别名]
# 或者: from graph_tool.Graph import edge_properties[col] [as 别名]
def graph_from_dataframes(vertex_df, edge_df):
'''Re-creates a Graph object with PropertyMaps taken
from the vertex_df and edge_df DataFrames
Paramters:
==========
verex_df: a DataFrame with an index named 'vertex_index'
edge_df: a DataFrame with a multi-index named ('source', 'target')
Returns:
========
graph: a grah-tool Graph with PropertyMaps copied
from the columns of the input DataFrames
'''
graph = Graph(directed=True)
vertex_index = vertex_df.index.get_level_values(level='vertex_index')
vertices = graph.add_vertex(n=vertex_index.shape[0])
for col in vertex_df.columns:
dtype = ALIASES[vertex_df[col].dtype.name]
prop = graph.new_vertex_property(dtype)
prop.a = vertex_df[col]
graph.vertex_properties[col] = prop
src = edge_df.index.names.index('source')
trgt = edge_df.index.names.index('target')
### TODO: use the list edge creation
for tup in edge_df.index:
source, target = tup[src], tup[trgt]
edge = graph.add_edge(source, target)
for col in edge_df.columns:
dtype = ALIASES[edge_df[col].dtype.name]
prop = graph.new_edge_property(dtype)
prop.a = edge_df[col]
graph.edge_properties[col] = prop
return graph