Good morning all I am trying to process a lot of data, and I need to group data, look at the group, then set a value based on the other entries in the group, but I want to set the value in a column in the full dataset. What I can't figure out is how I can use the group to write back to the main dataframe. So as an example, I created this data frame import pandas as pd data = [{ "class": "cat", "name": "Fluffy", "age": 3, "child": "Whiskers", "parents_in_group": "" }, { "class": "dog", "name": "Spot", "age": 5 }, { "class": "cat", "name": "Whiskers", "age": 7 }, { "class": "dog", "name": "Rover", "age": 2, "child": "Spot" }] df = pd.DataFrame(data) df So as an example, lets say that I want to set the parrents_in_group to a list of all the parrents in the group, easy to do for name, group in group_by_class: mask = group["child"].notna() print("This is the parrent in group") print(group[mask]) parent_name = group[mask]["name"].values[0] print(f"This is the parent name: {parent_name}") group["parents_in_group"] = parent_name print("And now we have the name set in group") print(group) That updates the group, but not the actual data frame. So how would I go about writing this information back to the main data frame Using the name and search This works, but seems a bit untidy for name, group in group_by_class: mask = group["child"].notna() parent_name = group[mask]["name"].values[0] df.loc[df['class'] == name, 'parents_in_group'] = parent_name df Using group How would I go about using group to set the values, rather than searching for the name that the group was created by. Or are there better ways to going about it. The real challenge I'm having is that I need to get the group, find some specific values in the group, then set some fields based on the data found. Any help of course welcome. Continue reading...