Первый список в "fav_colour" и "names" взят из "Tower Hamlets".
Второй список в "fav_colour" и "names" взят из "Waltham Forrest".
Пожалуйста, смотрите вывод скрипта и CURRENT ниже:
import pandas as pd
import numpy as np
fav_colour = [['blue', 'yello', 'indigo', 'jasmine', 'green', 'black'], ['yellow','purple', 'red', 'beige']]
names = [['melanie', 'jess', 'sean', 'tom', 'arjun', 'brandon'],['scotty', 'harry', 'chloe', 'emily']]
boroughs = ['Tower Hamlets','Waltham Forrest']
No_of_rows = [len(name) for name in names] #using length to repeat rows in some way??
indexs4 = list(range(0,2))
df1 = [pd.DataFrame(zip(names[i], fav_colour[i], boroughs[i]), columns = ['names','fav', 'boroughs']) for i in indexs4]
df = pd.concat(df1)
"fav_colour" и "имена" имеют отношение один к одному.
"Имена" и "fav_colour" имеют отношения один-ко-многим с районами
Я хочу установить отношения один-ко-многим с "fav_colour", "name" и "boroughs" в качестве столбцов как показано ниже:
Желаемый выход:
names fav boroughs
0 melanie blue Tower Hamlets
1 jess yello Tower Hamlets
2 sean indigo Tower Hamlets
3 tom jasmine Tower Hamlets
4 arjun green Tower Hamlets
5 brandon black Tower Hamlets
0 scotty yellow Waltham Forrest
1 harry purple Waltham Forrest
2 chloe red Waltham Forrest
3 emily beige Waltham Forrest
Токовый выход:
names fav boroughs
0 melanie blue T
1 jess yello o
2 sean indigo w
3 tom jasmine e
4 arjun green r
5 brandon black
0 scotty yellow W
1 harry purple a
2 chloe red l
3 emily beige t