Now hello, what I would like is showing hirarchy of likes. People from column 1 can like someone from column 2. Basically it'd be ideal having 4 columns A, B, C, D which show for every person who they like and for that person the next one etc. Basically from (a, b) tuples to (a, b), (b, c), (c, d). I only know it must be recursive but I have for example no clue how you can check in Pandas different columns and check them and that in a recursive manner. So multiple people can like someone but not everyone has to like someone. But if that's the case, it can only happen over 3 people.
So, I have a dataframe like this:
import pandas as pd
d = {'col1': ['Ben', 'Mike', 'Carla', 'Maggy', 'Josh', 'Kai', 'Maria', 'Sophie'], 'col2': ['Carla', 'Carla', 'Josh', 'Ben', 'Lena', 'Maggy', 'Mike', 'Chad']}
df = pd.DataFrame(data=d)
df
I would like an output like this:
d = {'A': ['Ben', 'Mike', 'Carla', 'Maggy', 'Josh', 'Kai', 'Maria', 'Sophie'], 'B': ['Carla', 'Carla', 'Josh', 'Ben', 'Lena', 'Maggy', 'Mike', 'Chad'], 'C': ['Josh', 'Josh', 'Lena', 'NA', 'NA', 'Ben', 'Carla', 'NA'], 'D': ['Lena', 'Lena', 'NA', 'NA', 'NA', 'NA', 'Josh', 'NA']}
df = pd.DataFrame(data=d)
df
I think the rules are like that:
- Someone (column B) can be liked from someone (from column A) but that somebody (column B) doesn't like anyone. (like Chad doesn't like anyone)
- Someone can be liked by only one person (A -> B -> NA -> NA)
- Someone can like somebody, that somebody likes someone else. (A -> B -> C -> NA)
- Someone can like someone, who likes someone else. And that someone likes someone as well. (A -> B -> C-> D -> NA)
How can I achieve this? Thank you