I have two dataframes df and tf like as given below
df = [{"unique_key": 1, "test_ids": "1.0,15,2.0,nan"}, {"unique_key": 2, "test_ids": "51,75.0,11.0,NaN"},{"unique_key": 3, "test_ids":np.nan},
{"unique_key": 4, "test_ids":np.nan}]
df = pd.DataFrame(df)
test_ids,status,revenue,cnt_days
1,passed,234.54,3
2,passed,543.21,5
11,failed,21.3,4
15,failed,2098.21,6
51,passed,232,21
75,failed,123.87,32
tf = pd.read_clipboard(sep=',')
I would like to link the unique_key column from df to the tf dataframe
For ex: I will show my output below (that's easy to understand than text)
I was trying something like below
for b in df.test_ids.tolist():
for a in b.split(','):
if a >= 0: # to exclude NA values from checking
for i in len(test_ids):
if int(a) == tf['test_ids'][i]:
tf['unique_key'] = df['unique_key']
But this is neither efficient nor elegant to solve my problem.
Is there any other better way to achieve the expected output shown below?
