The for statement overwrites the looped content for each purchase order number, and
When stored as a variable, only the last action was stored.
There is no problem that I can see the looped contents when I display it in print.
Please tell me how to write the code to store all looped contents in the group_list variable.
for i, group training_data.groupby('Order Number'):
print(group)
group_list=group.append(group, ignore_index=True)
group_list
As you can see in the comments, I don't think you need to go out of your way to turn the for statement, but I would like to point out the reason for the unexpected behavior.
The for statement overwrites the looped content for each purchase order number, and when stored as a variable, only the last action was stored.
Because it is group.append(group), it is in the state that ignores all previous data and overwrites the group_list with two lines of the same data.
If you want to merge, it must be group_list.append(group).
for i, group training_data.groupby('Order Number'):
print(group)
group_list=group_list.append(group, ignore_index=True)
group_list
© 2024 OneMinuteCode. All rights reserved.