我有一个数据框如下:
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 的新手,还不熟悉库。
最佳答案
尝试 reindex
和 repeat
df=df.reindex(df.index.repeat(df.Count)).assign(Count=1)
关于python - 展开 python pandas 数据框中的行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59120375/