【发布时间】:2016-12-08 14:14:01
【问题描述】:
我有这个数据框:
ID key
0 1 A
1 1 B
2 2 C
3 3 D
4 3 E
5 3 E
当有重复的IDs 时,我想创建额外的key 列以将数据存储在key 列中
这是输出的sn-p:
ID key key2
0 1 A B # Note: ID#1 appeared twice in the dataframe, so the key value "B"
# associated with the duplicate ID will be stored in the new column "key2"
完整的输出应如下所示:
ID key key2 key3
0 1 A B NaN
1 2 C NaN NaN
2 3 D E E # The ID#3 has repeated three times. The key of
# of the second repeat "E" will be stored under the "key2" column
# and the third repeat "E" will be stored in the new column "key3"
任何建议或想法我应该如何解决这个问题?
谢谢,
【问题讨论】:
标签: python regex pandas dataframe format