I have 2 snippets which are giving me different outputs. The first snippet gives me the desired output but I want to replicate the same output with the 2nd snippet.
Snippet 1:
Top= pd.DataFrame({'A':['Hello', 'World']})
insrt1= pd.DataFrame({'A': [f'Appended Item-1x']})
df=Top['A'].append(insrt1['A'])
print(df)
Out:
0 Hello
1 World
0 Appended Item-1x
Name: A, dtype: object
The 2nd snippet yields a different output due to the for loop. How can I achieve the same output as in snippet 1?
Snippet2
Top= pd.DataFrame({'A':['Hello', 'World']})
Frst=['1','2']
Scnd=['x','y']
d={}
for num1 in Frst:
for num2 in Scnd:
key = f'-OE{num1}{num2}-'
insrt2 = pd.DataFrame({'A': [f'Appended Item-{num1}{num2}']})
d[key] = insrt2
df=Top['A'].append(d['-OE1x-'])
print(df)
Out:
0 A
0 Hello NaN
1 World NaN
0 NaN Appended Item-1x
Ahas valuesAppended Item-1x,...1y,...2x,...2y? Please be specific when asking others for help.