使用 Excel 文件时获取"TypeError: only integer scalar arrays can be converted to a scalar index"



我有一个Excel文件,其中一列(x(行填充了dictionary。对这列执行的任何操作都会给我这个错误:df.x,df.x.describe((。无法处理它。

我已经通过手动创建相同的df进行了检查,以检查它是否不是类型问题,但不是。

b=[{'maker':'renault','model':'twingo','year':'null','motor':'null','fitment':'null'}]
c=[5500]
df= pd.DataFrame({'country':a, 'x':b ,'sold':c}) 

你遇到过类似的问题吗?

以下是完整的错误消息:

<ipython-input-11-04b9e65f2265> in <module>
1 maker=[]
----> 2 for idx, row in test['x'].iteritems():
3     l=row.keys()
4 
5     if 'maker' in l:
~Anaconda3libsite-packagespandascoreframe.py in __getitem__(self, key)
2774                 if self.columns.nlevels > 1:
2775                     return self._getitem_multilevel(key)
-> 2776                 return self._get_item_cache(key)
2777 
2778         # Do we have a slicer (on rows)?
~Anaconda3libsite-packagespandascoregeneric.py in _get_item_cache(self, item)
3584         res = cache.get(item)
3585         if res is None:
-> 3586             values = self._data.get(item)
3587             res = self._box_item_values(item, values)
3588             cache[item] = res
~Anaconda3libsite-packagespandascoreinternalsmanagers.py in get(self, item)
966                         raise ValueError("cannot label index with a null key")
967 
--> 968             return self.iget(loc)
969         else:
970 
~Anaconda3libsite-packagespandascoreinternalsmanagers.py in iget(self, i)
983         Otherwise return as a ndarray
984         """
--> 985         block = self.blocks[self._blknos[i]]
986         values = block.iget(self._blklocs[i])
987 
TypeError: only integer scalar arrays can be converted to a scalar index

我找到了。重命名列时出错
感谢

相关内容

最新更新