我想知道在用GraphFrame
构造一个图之后,有没有办法更新顶点(或边)值?我有一个图,它的顶点有这些['id', 'name', 'age']
列。我已经写了一个代码,创建新时代的顶点,它的工作非常好。然而,当我想将这些新的顶点分配给旧图形的顶点时,我得到了can't set attribute
错误
from graphframes import GraphFrame
import pyspark.sql.functions as F
# Vertice DataFrame
v = spark.createDataFrame([
("a", "Alice", 34),
("b", "Bob", 36),
("c", "Charlie", 30),
], ["id", "name", "age"])
# Edge DataFrame
e = spark.createDataFrame([
("a", "b", "friend"),
("b", "c", "follow"),
("c", "b", "follow"),
], ["src", "dst", "relationship"])
# Create a GraphFrame
g = GraphFrame(v, e)
# Update Vertices
updated_vertices = (
g.vertices
.withColumn('new_age', F.lit(10))
.select(
'id',
'name',
F.col('new_age').alias('age')
)
)
# Set new vertices
g.vertices = updated_vertices
AttributeError: can't set attribute
我应该重建一个新的图形对象吗?还是有更好的方法
多谢各位
您必须创建一个新的图形对象才能进行更新。但是,由于graphframe对象只有两个数据帧,因此可以像这样进行更新
所以保持相同的名字
相关问题 更多 >
编程相关推荐