另一种执行此方法的方法是使用
groupy,
apply(list)然后使用转换列表值到单独的列
Series.values.tolist()
# Groupby and get the values in a list per unique value of the Date columndf = df.groupby('Date').String.apply(list).reset_index() Date String0 2016-06-30 [d, e, f]1 2016-08-01 [a, b, c]# Convert the values from the list to seperate columns and after that drop the String columndf[['Column1', 'Column2', 'Column3']] = pd.Dataframe(df.String.values.tolist(), index=df.index)df.drop('String', axis=1, inplace=True) Date Column1 Column2 Column30 2016-06-30 d e f1 2016-08-01 a b c


