Thursday 10 August 2023

Match a row with the rows of another table to be able to classify the row in Databricks

How Can I Classify the values of the Clients table with the values of the rows of the Combinations table?,

I decide to create a combinations table to develop all combinations from main row.(Clients Table )

I am planning to check that the row of the customers coincides with a row of the combinations table to classify it as sector B.(Combinations Table)

I have this flow but Dtabricks returns error:

 for i,j in select_df.iterrows():
      for u,v in dfCombinacionesDias.iterrows():
          if((select_df["MONDAY"][i] == registro["LUNES"][u]) and (select_df["TUESDAY"][i] == registro["MARTES"][u]) and (select_df["WEDNESDAY"][i] == registro["MIERCOLES"][u]) and (select_df["THURSDAY"][i] == registro["JUEVES"][u]) and (select_df["FRIDAY"][i] == registro["VIERNES"][u]) and (select_df["SATURDAY"][i] == registro["SABADO"][u]) and (select_df["SUNDAY"][i] == registro["DOMINGO"][u])):
        
             Sector = "B"
          else:
            Sector = "A"
        
vSubSeq = "('{}','{}')".format(select_df["IDClient"][i],Sector)
sqlInsertSequence = "Insert into {0}.{1} values {2}".format(dSCHEMA, Table, vSubSeq,vdataDeltaPath)
print(sqlInsertSequence)
dfTables = spark.sql(sqlInsertSequence)

I add the image with the diferents tables(Clients, Combinations and Sector) Tables

I think that I need a for to loop a table row by row(Combinations table) to compare with a row in clients table if there is a match I save this value in a new table(sector table) and obviously will exist other for to loop the clients table.But I would like to know an algorithm that helps look tables to compare?



from Match a row with the rows of another table to be able to classify the row in Databricks

No comments:

Post a Comment