【问题标题】:pynock: unable to convert a graph partition into a dataframepynock:无法将图形分区转换为数据框
【发布时间】:2022-10-07 13:52:10
【问题描述】:

考虑下面的示例,我正在尝试创建一个小的单分区图并将其导出到 pandas 数据框:

from pynock import Edge, Node, Partition

# create a new partition
p = Partition(part_id=1)

# add nodes to the partition
for k in range(3):
    # create a node with an edge hardcoded to link to node 1
    _node = Node(node_id=k, name=f\"{k}\")
    _edge = Edge(node_id=1)
    _node.add_edge(_edge)

    # add the node to the partition
    p.add_node(_node)

# convert to dataframe
p.to_df()
# will print an empty dataframe

当我使用print(p) 检查分区时,我可以看到节点已添加到分区中。为什么数据框是空的?

    标签: python pandas pynock


    【解决方案1】:

    除了将节点添加到分区之外,还应使用p.create_node_name(...) 创建分区节点名称:

    from pynock import Edge, Node, Partition
    
    # create a new partition
    p = Partition(part_id=1)
    
    # add nodes to the partition
    for k in range(3):
        # create a node with an edge hardcoded to link to node 1
        _node = Node(node_id=k, name=f"node_{k}")
        _edge = Edge(node_id=1)
        _node.add_edge(_edge)
    
        # add the node to the partition
        p.create_node_name(k)
        p.add_node(_node)
    
    # convert to dataframe
    p.to_df()
    

    【讨论】:

      猜你喜欢
      • 2019-07-13
      • 1970-01-01
      • 2018-12-17
      • 2020-02-16
      • 1970-01-01
      • 1970-01-01
      • 2022-08-11
      • 2017-05-27
      • 2023-03-17
      相关资源
      最近更新 更多