I am trying to make a diagram tree in graphviz.Digraph, I am using Pandas dataframe. By the below query, I am getting the processid’s and their dependents id’s in a form of a dictionary
dependent = df.groupby('dependent_processid')['Processid'].apply(list).to_dict() print(dependent) #output: {6720: [6721], 6721: [6722, 6724, 6725], 6725: [6723, 6726], 6753: [7177]}
But I want the data in below format:
6720-> {6721} 6721-> {6722, 6724, 6725} 6725-> {6723, 6726} ....and so on...
Can someone please help me return pandas dataframe output in such format?
Advertisement
Answer
Are you wanting this:
def demo(k,v): return f'{k} -> {v}' dependent = df.groupby('dependent_processid')['Processid'].apply(set).to_dict() for k, v in dependent.items(): print(demo(k,v))
Output:
6720-> {6721} 6721-> {6722, 6724, 6725} 6725-> {6723, 6726} ...