Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/334.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 如何以整数形式返回最短路径距离?_Python_Apache Spark_Pyspark_Shortest Path_Graphframes - Fatal编程技术网

Python 如何以整数形式返回最短路径距离?

Python 如何以整数形式返回最短路径距离?,python,apache-spark,pyspark,shortest-path,graphframes,Python,Apache Spark,Pyspark,Shortest Path,Graphframes,我使用Pyspark的内置最短路径函数返回从每个顶点到给定目的地的最短路径。但是,它返回的格式为[1->0],如下所示。如何让它以整数形式返回单个距离,以便在[1->0]的情况下只返回0 我的代码如下: def get_shortest_distances(graphframe, dst_id): result = graphframe.shortestPaths(landmarks=[dst_id]) result.show() g = GraphFrame(vertice

我使用Pyspark的内置最短路径函数返回从每个顶点到给定目的地的最短路径。但是,它返回的格式为[1->0],如下所示。如何让它以整数形式返回单个距离,以便在[1->0]的情况下只返回0

我的代码如下:

def get_shortest_distances(graphframe, dst_id):

    result = graphframe.shortestPaths(landmarks=[dst_id])
    result.show()

g = GraphFrame(vertices, edges)

get_shortest_distances(g, '1')
输出:

+---+---------+
| id|distances|
+---+---------+
|  1| [1 -> 0]|
|  3| [1 -> 2]|
|  2| [1 -> 1]|
|  4|       []|
|  5|       []|
|  0| [1 -> 1]|
+---+---------+
期望输出:

+---+---------+
| id|distances|
+---+---------+
|  1|       0 |
|  3|       2 |
|  2|       1 |
|  4|    none |
|  5|    none |
|  0|       1 |
+---+---------+

结果的结构/类型是什么?
?如果运行printSchema(),我会得到以下结果:root |--id:string(nullable=true)|--distance:map(nullable=true)|--key:string | |--value:integer(valuecontainsnall=false)try
F.map(值('distance')
?@mck你的意思是什么?
g2=g.withColumn(“距离”,F.map_值(“距离”)