我想按一列分组,并用另一列中显示的值序列创建一个新列。
import pandas as pd
groups = [1,1,1,2,3,3,3,3,4,4]
sequence = ['A','B','C','A','B','C','A','B','C','A']
df = pd.DataFrame({'to_group':groups, 'sequences':sequence})
desired_group = [1,2,3,4]
desired_sequence = [['A','B','C'], ['A'],['B','C','A','B'],['C','A']]
desired_df = pd.DataFrame({'desired_groups':desired_group, 'desired_sequences':desired_sequence})
在GroupBy pandas函数之后,我似乎看不到任何可以帮助这种情况的函数。任何帮助表示赞赏,谢谢。