【发布时间】:2020-10-12 15:27:36
【问题描述】:
我在df_1 中有以下数据集,我想将其转换为df_2 的格式。在df_2 中,我已将df_1 的列转换为df_2 中的行(不包括UserId 和Date)。我查找了类似的答案,但他们提供的解决方案并不复杂。有没有简单的方法来做到这一点?
df_1
UserId Date -7 -6 -5 -4 -3 -2 -1 0 1 2 3 4 5 6 7
87 2011-05-10 18:38:55.030 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0
487 2011-11-29 14:46:12.080 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0
21 2012-03-02 14:35:06.867 0 1 0 1 2 0 2 2 0 1 2 2 1 3 1
df_2
day | count
-7 0
-7 0
-7 0
-6 0
-6 0
-6 1
-5 0
-5 1
-5 0
. .
. .(Similarly for other columns in between)
. .
6 0
6 0
6 3
7 0
7 0
7 1
【问题讨论】:
标签: python python-3.x pandas dataframe pandas-groupby