First, I'm trying to do this as a vector operations due to large dataset.
import pandas as pd
sub_list = [{"uniqueId": "123456", "ref_idx": 1},
{"uniqueId": "123457", "ref_idx": 2},
{"uniqueId": "123458", "ref_idx": 3},
{"uniqueId": "123459", "ref_idx": 4},
{"uniqueId": "123460", "ref_idx": 5},
{"uniqueId": "123461", "ref_idx": 6}]
primary_list = [{"uniqueId": "123456"},
{"uniqueId": "123457"},
{"uniqueId": "123458"},
{"uniqueId": "123459"},
{"uniqueId": "123460"},
{"uniqueId": "123461"},
{"uniqueId": "123462"},
{"uniqueId": "123463"},
{"uniqueId": "123464"},
{"uniqueId": "123465"}]
subset_df = pd.DataFrame(sub_list)
primary_df = pd.DataFrame(primary_list)
subset_df.set_index("uniqueId", inplace=True)
primary_df.set_index("uniqueId", inplace=True)
primary_df["ref_idx"] = primary_df.loc([subset_df.index]["ref_idx"])
The issue is with the last statement. I've tried various iterations of how to acquire the slice from the subset_df (ref_idx value) and populate it to the primary_df as a new column. Of course those records that doen't appear in the subset_df will not have value (NaN) in the primary_df. That's ok.
Just not sure the correct syntax.
I'm seeing errors like TypeError: list indices must be integers or slices, not str; call() takes from 1 to 2 positional arguments but 3 were given which happens when one separates the ([subset_df.index], ["ref_idx"])
Basically, use the index to qualify the data but return the ref_idx value.
Ideas?