python - 根据动态列数将列添加到数据框的末尾
问题描述
我有一个数据框,其中列数逐月变化。我想在每个数据框的末尾创建 3 个空列。
我使用insert
,但由于列数逐月变化,我留下了错误
IndexError: index 59 is out of bounds for axis 0 with size 58
我的代码:
netnewprocess.insert(59, 'date', '')
netnewprocess.insert(60, 'Analyst Review', '')
netnewprocess.insert(61, 'SM Review', '')
解决方案
如果您只是像这样添加一列,它将将该列附加到 DataFrame 的右侧,并且您不需要指定索引:
netnewprocess['date'] = ''
netnewprocess['Analyst Review'] = ''
netnewprocess['SM Review'] = ''
推荐阅读
- laravel - Laravel Livewire 使用媒体库包上传图片
- netbeans - NetBeans 12.1 Xdebug 3.0.2 断点未中断
- graph - 如何导出 Kolmogorov–Smirnov?
- javascript - Javascript 中的逻辑运算符 AND/OR 短马戏团
- javascript - getJSON 不从服务器加载数据
- google-cloud-platform - GKE 日志存储在哪里?
- java - 同一个数据库的不同应用
- mongodb - MongoDB 中的 $nin 运算符是否有最大限制?
- python - 从 Github 运行安装和导入时出错
- sql - 基于另一个组在组中插入或更新行