繁体   English   中英

展开 python pandas 数据框中的行

[英]Expand rows in python pandas dataframe

我有一个数据框如下:

Name Description Count
a     This is a   3
b     This is b   2
c     This is c   1

我想按如下方式修改此数据框:

Name Description Count
a     This is a   1
a     This is a   1
a     This is a   1
b     This is b   1
b     This is b   1
c     This is c   1

基本上,通过特定列的值复制每一行。

我是 python 的新手,还不熟悉库。

尝试使用repeat reindex

df=df.reindex(df.index.repeat(df.Count)).assign(Count=1)

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM