全,
希望在df中添加一个新列,该列的分段号以批形式递增。输出的一个例子是这样的情况:段数随3条记录的批次递增:
Index Animal Segment
0 Dog 1
1 Cat 1
2 Cat 1
3 Bear 2
4 Bird 2
5 Dog 2
6 Dog 3
7 Dog 3
8 Cat 3
9 Bear 4
10 Bear 4
11 Lion 4
12 Dog 5
13 Lion 5
14 Cat 5不确定在潘达斯实现这一目标的最佳方法。我知道在常规python中,我会逐行执行循环和增量I,但是不知道如何在Pandas中这样做。
谢谢你的帮助。
发布于 2018-12-13 13:48:45
你能试一下吗。
df['Segment']=df.index // 3 + 1
dfhttps://stackoverflow.com/questions/53763190
复制相似问题