Простой фрейм данных, и я хочу создать списки, используя GroupBy.
![enter image description here](https://i.stack.imgur.com/MS89V.png)
import pandas as pd
data = {'Name': ["David","David","David","David","Kate","Kate","Kate","Kate","Kate","Kate"],
'Truck' : ["PLO8318","PLO6372","PLO6473","PLO8249","PLO6540","PLO7623","PLO8036","PLO6314","PLO7791","PLO7848"],
}
df = pd.DataFrame(data)
df_1 = df.groupby('Name')['Truck'].apply(list)
df_1 = df_1.to_frame().reset_index()
for index, row in df_1.iterrows():
print (row['Name'], row['Truck'])
Вывод:
('David', ['PLO8318', 'PLO6372', 'PLO6473', 'PLO8249'])
('Kate', ['PLO6540', 'PLO7623', 'PLO8036', 'PLO6314', 'PLO7791', 'PLO7848'])
Как мне распечатать как:
David = ['PLO8318', 'PLO6372', 'PLO6473', 'PLO8249']
Kate = ['PLO6540', 'PLO7623', 'PLO8036', 'PLO6314', 'PLO7791', 'PLO7848']