I have two data frames.
All the NaN of df1 have to fill by df2 by matching 'Group'. Can repeat matching and filling by 'Repeat' times.
df1 = pd.DataFrame({'Group': ['xx', 'yy', 'zz', 'x', 'x', 'x','z','y','y','y','y'], 'Name': ['A', 'B', 'C', None, None, None, None, None, None, None, None], 'Value': [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11]})
df2 = pd.DataFrame({'Name': ['A', 'A', 'B', 'B'], 'Group': ['x', 'y', 'z', 'y'], 'Repeat': [3, 2, 1, 2]})
The final data frame df will look like-
Also looking for the fastest run time.
I did this
for index2, row2 in df2.iterrows():
for i in range(0,row2[2]):
for index1 in df1.index:
if df1.iloc[index1, 1] == row2[1] and df1.iloc[ndex1, 1] == 'NaN':
df1.iloc[ndex1, 1] = row2[0]
break
Looking for faster simpler solution.