I'm currently learning python and I'm stuck to resolve a problem. I have a simple genealogy table (2 columns: parent_id, child_id), I would like to create a raw for each path and create a unique ID (keep the same ID if last child is the same). Something like this:enter image description here I tried several methods unsuccessfully. Do you have some ideas? Thank you
Asked
Active
Viewed 25 times
0
-
1what does you mean "create a raw" ? you can put this into a dataframe or a dict on python. – D.L Sep 14 '22 at 17:52
-
I don't if it's the good term, I would like to do a table like this: https://i.stack.imgur.com/qiaMy.png – user19996190 Sep 15 '22 at 13:20
1 Answers
0
You could put this into a dataframe or a dictionary.
Here is the dataframe example:
import io
import pandas as pd
# example dable
x = '''
parent, child 1, child 2, child 3, child 4, id
a, b, c, d, e, Id1
g, f, e, , , Id1
h, i, j, k, , Id2
i, j, m, k, , Id2
'''
# data into a dataframe
data = io.StringIO(x)
df = pd.read_csv(data, sep=', ')
df
which returns this:

D.L
- 4,339
- 5
- 22
- 45