Python/Pandas/Numpy-迭代一个数据集并更新另一个数据集中的所有事件
我有两个数据集: 群集ID表: 关系\u ID集群\u IDPython/Pandas/Numpy-迭代一个数据集并更新另一个数据集中的所有事件,python,databricks,Python,Databricks,我有两个数据集: 群集ID表: 关系\u ID集群\u ID 00000000 100000000 11 000000002000000011 00000000 3 000000000 33 00000000 4 000000000 44 00000000 5 000000000 55 00000000 6 000000000 33 00000000 7 000000000 44 00000000 800 000000000 44 集群ID更新表: 从关系ID到关系ID 000000000100
00000000 100000000 11
000000002000000011
00000000 3 000000000 33
00000000 4 000000000 44
00000000 5 000000000 55
00000000 6 000000000 33
00000000 7 000000000 44
00000000 800 000000000 44 集群ID更新表:
从关系ID到关系ID
000000000100000003
000000000 5 00000000 4 集群ID更新表用于更新集群ID表。集群ID表中的所有集群ID的To_relationship_ID必须替换为From_relationship_ID的集群ID。 在上述情况下,使用2行集群\u ID\u Update\u表:
关系\u ID集群\u ID
00000000 100000000 11
000000002000000011
00000000 3 000000000 11
00000000 4 000000000 55
00000000 5 000000000 55
00000000 6 000000000 11
00000000 7 000000000 55
00000000 800 000000000 55 数据集的大小为:
集群ID表:2566787
集群ID更新表:417325 我需要在MS Databricks笔记本中实现这一点。我使用了numpy循环并使用下面的代码进行更新,但代码运行时间太长
#Cluster_ID_table - Dataframe with Cluster_ID_table data
#Cluster_ID_Update_table - Dataframe with Cluster_ID_Update_table data
Cluster_ID_Update_np=np.array(Cluster_ID_Update_table[['From_Relation_ID','To_Relation_ID']])
Cluster_ID_table_np=np.array(Cluster_ID_table[['Relation_ID','Cluster_ID']])
rows = Cluster_ID_Update_np.shape[0]
cols = Cluster_ID_Update_np.shape[1]
for row in range(0, rows):
TOrelid = Siebel_REL_np[row][0]
FROMrelid = Siebel_REL_np[row][1]
TOclusterid = Cluster_ID_table.loc[Cluster_ID_table.REL_ID == TOrelid,'CLUSTER_ID'].max()
FROMclusterid = Cluster_ID_table.loc[Cluster_ID_table.REL_ID == FROMrelid,'CLUSTER_ID'].max()
Cluster_ID_table_np[:,1][Cluster_ID_table_np[:,1] == FROMclusterid] = TOclusterid
在Databricks笔记本中快速运行此功能的任何帮助都将非常有用