So I am trying to add each equation only once to my dictionary and put in in a Dataframe. However, every instance in the for loop is being added to the Dataframe multiple times.
below is a sample output.
Eq ADD Eq SUB
0 (16 + 100 = , 86 + 77 = , 8 + 75 = ... (78 - 79 = , 72 - 84 = , 25 - 78 = ...
1 (16 + 100 = , 86 + 77 = , 8 + 75 = ... (78 - 79 = , 72 - 84 = , 25 - 78 = ...
2 (16 + 100 = , 86 + 77 = , 8 + 75 = ... (78 - 79 = , 72 - 84 = , 25 - 78 = ...
3 (16 + 100 = , 86 + 77 = , 8 + 75 = ... (78 - 79 = , 72 - 84 = , 25 - 78 = ...
4 (16 + 100 = , 86 + 77 = , 8 + 75 = ... (78 - 79 = , 72 - 84 = , 25 - 78 = ...
5 (16 + 100 = , 86 + 77 = , 8 + 75 = ... (78 - 79 = , 72 - 84 = , 25 - 78 = ...
Below is my code.
import random
import pandas as pd
_dict_add = {}
_dict_sub = {}
for i in range(0, 50):
value1_add = random.randint(0, 100)
value2_add = random.randint(0, 100)
eq_add = {str(value1_add) + " + " + str(value2_add) + " = ": value1_add + value2_add}
_dict_add.update(eq_add)
value1_sub = random.randint(0, 100)
value2_sub = random.randint(0, 100)
eq_sub = {str(value1_sub) + " - " + str(value2_sub) + " = ": value1_sub - value2_sub}
_dict_sub.update(eq_sub)
dataframe = pd.DataFrame({
'Eq ADD': _dict_add.keys(),
'Eq SUB': _dict_sub.keys()
})
print(dataframe)
Why does this happen? I would assume my loop is adding one instance only once. But that is not the case in my Dataframe. How do I prevent this?
EXPECTED OUTPUT
0 1
0 79 + 15 = 26 - 36 =
1 93 + 42 = 70 - 17 =
2 3 + 27 = 15 - 51 =
3 70 + 72 = 40 - 27 =
4 6 + 99 = 88 - 35 =
5 30 + 10 = 97 - 84 =