在Windows中使用ValueError运行Python脚本:列的长度必须与键的长度相同

时间:2020-02-27 15:10:30

标签: python-3.x windows

我可以在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

0 个答案:

没有答案