python - 将列中的值重复 n 次
问题描述
我有以下数据框
Code
1
3
4
5
我想将每个代码值重复 5 次,以便输出为:
Code
1
1
1
1
1
3
3
3
3
3
4
4
4
4
4
5
5
5
5
5
np.repeat 似乎不适用于数据帧
解决方案
You can repeat
the index:
df.loc[df.index.repeat(5)]
推荐阅读
- raster - 如何从 netcdf 文件中获取日期和深度并合并到数据框中?
- node.js - 在 Node.JS 中跨测功机保存对象的最佳方法
- mysql - 将 MySQL 查询复制并粘贴到命令行中不起作用
- google-colaboratory - 可视化对象检测图时 TensorBoard 挂起
- arrays - 如何将文件添加到 bash 数组
- spring - Crontab 无法启动 Maven 服务
- c++ - 连接变量时,目标特定变量定义不起作用
- prometheus - 总结一个已经是比率的指标
- javascript - 通过JS浏览器控制台直接执行代码
- javascript - Electron 在浏览器窗口中使用 ipcRenderer 获取对象选定对象的类名