I am working on a dataset and I have this data frame which is only a part of the dataset:
def make_decision(x):
decisions=pd.DataFrame(([{
"requests":" ",
"name":fake.name(),
# ****** NEED TO INSERT "IDS" HERE ****
"decision":[{
"ID":random.randint(0,400000),
# ....
}],
} for i in range(x)
]))
return decisions
decisions_data=make_decisions(100)
I need to use the same ids for multiple locations. For this I created another data frame:
def make_id(x):
ids=pd.DataFrame(([{
"id":random.randint(10000,1000000)
} for i in range(x)]))
return ids
ids_data=make_id(100)
inside make_decisions, I tried:
#decisions.decision
decisions["decision"].insert(loc=0,
column="ID",
value=ids.data)
This did not work. Is there any easy way that I can insert a column inside nested data in pandas? A workaround is to create another data frame decision, insert the ids here and then insert the decision into the decisions, which is not good if I you have a deep nested dataset.