您好, 欢迎来到 !    登录 | 注册 | | 设为首页 | 收藏本站

按日期将行旋转到列

按日期将行旋转到列

另一种执行此方法方法是使用groupyapply(list)然后使用转换列表值到单独的列Series.values.tolist()

# Groupby and get the values in a list per unique value of the Date column
df = df.groupby('Date').String.apply(list).reset_index()

    Date        String
0   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 column
df[['Column1', 'Column2', 'Column3']] = pd.DataFrame(df.String.values.tolist(), index=df.index)
df.drop('String', axis=1, inplace=True)


    Date        Column1 Column2 Column3
0   2016-06-30  d       e       f
1   2016-08-01  a       b       c
其他 2022/1/1 18:42:26 有565人围观

撰写回答


你尚未登录,登录后可以

和开发者交流问题的细节

关注并接收问题和回答的更新提醒

参与内容的编辑和改进,让解决方法与时俱进

请先登录

推荐问题


联系我
置顶