python-3.x - 在 Windows 中使用 ValueError 运行 Python 脚本:列的长度必须与键的长度相同
问题描述
我可以在 MacOS10 中成功运行我的 Python3.7 脚本,但是在最新的 Windows10 Enterprise 中运行时,我的 Python 代码中显示如下错误,不确定是否有任何解决方案可以修复?
我的代码示例数据如下:
A B C D Month
0 11 23 23 25 1
1 11 24 NA 26 2
2 12 20 18 18 1
3 12 NA 20 10 2
col=['Month','A','B','C']
df[col] = df[col].groupby(['A'], sort=False, as_index=False).ffill()
Windows环境下的错误信息如下:
df[col] = df[col].groupby(['A'], sort=False, as_index=False).ffill()
File "C:\Users\....\anaconda3\lib\site-packages\pandas\core\frame.py", line 3469, in __setitem__
self._sentitem_array(key, value)
File "C:\Users\....\anaconda3\lib\site-packages\pandas\core\frame.py", line 3492, in _setitem_array
raise ValueError('Columns must be same length as key')
ValueError: Columns must be same length as key
解决方案
推荐阅读
- javascript - 想要一条消息出现然后走 - html?CSS?爪哇?
- css - 两列 Flexbox 布局中的“平衡段落”?
- unity3d - Unity 2D 教程“工具包工具”
- join - 如何在yii2中加入两个表格并在gridview中显示?
- javascript - 多个字段的 Jquery 自动完成(动态创建)
- unix - 出现意外的 JVM 参数(-Xms512M 和 -Xmx1024M)
- ios - iOS 向 JWplayer 7 控制栏添加一个按钮来控制
- vue.js - 动态添加自定义组件
- hibernate - 使用@RepositoryRestResource 插入级联,外键始终为空
- java - 在 jScrollPane 中调整 JTextArea 的大小?