0

Lets say I have a table:

tableName parentPartitionKey parentTableName
User entityId Entity
Employee entityId Entity
Customer entityId Entity
CreditType creditId Credit
Entity None None

Essentially, for each table I want to look for the parentTable’s partition key value. For example, table User has a parent table ‘Entity’. I want to return the Entity’s partition key value. How do I iterate through the data frame to find every table’s parentPartitionKey?

I tried using a np.where but this didn’t work. I am not trying to merge this data frame.

for idx, row in df.iterrows():
    print(row["parentPartitionKey"].where(row["parentTableName"] == row["tableName”])))
TylerH
  • 20,799
  • 66
  • 75
  • 101
Missm
  • 39
  • 5
  • What do you want as the output? – Onyambu Aug 22 '22 at 20:47
  • 1
    probably you should consider `df.set_index('tableName').drop('parentTableName', 1).to_dict()['parentPartitionKey']` – Onyambu Aug 22 '22 at 20:49
  • `df['parentTableName'].map(df.set_index('tableName')['parentPartitionKey'])` – mozway Aug 22 '22 at 20:51
  • I want it to return a single value for every row, so this could return a list. – Missm Aug 22 '22 at 20:51
  • These don't allow me to get a single value. – Missm Aug 22 '22 at 21:04
  • "I want to return the Entity’s partition key value" if your table is representative of a database, your entity table wouldn't have any referenced key value in there. Add the primary key of each table to the mix and maybe we have something. – Braiam Aug 27 '22 at 10:33

0 Answers0