在 pandas 中將數(shù)字?jǐn)?shù)據(jù)框轉(zhuǎn)換為整數(shù)時(shí)出錯(cuò)——“只能將整數(shù)標(biāo)量數(shù)組轉(zhuǎn)換為標(biāo)量索引”
我有一個(gè)大數(shù)據(jù)集,正在嘗試將僅包含數(shù)字?jǐn)?shù)據(jù)的“對(duì)象”列轉(zhuǎn)換為 python/pandas 中的“整數(shù)”數(shù)據(jù)類型。對(duì)于我嘗試的每個(gè)代碼,我都收到以下錯(cuò)誤:CODE SNIPPET (see below for options I have tried)PATH/frame.py in __setiten__(self, key, value) 3482 self._setitem_frame(key, value) 3483 elif isinstance(key, (Series, np.ndarray, list, Index)): -->3484 self._setiten_array(key, value) 3485 else: PATH/frame.py in _setitem_array(self, key, value) 3507 raise ValueError("Columns must be same length as key") 3508 for k1, k2 in zip(key, value.columns): -->3509 self[k1] = value[k2] 3510 else: 3511 indexer = self.loc._convert_to_indexer(key, axis=1) PATH/frame.py in __setitem__(self, key, value) 3485 else: 3486 #set column -->3487 self._set_item(key, value) 3488 3489 def _setitem_slice(self, key, value):PATH/frame.py in _set_item(self, key, value) 3562 3563 self._ensure_valid_index(value) -->3564 value = self._sanitize_column(key, value) 3565 NDFrame._set_item(self, key, value)PATH/frame.py in _sanitize_column(self, key, value, broadcast) 3778 if broadcast and key in self.columns and value.ndim == 1: 3780 if not self.columns.is_unique or isinstance(self.columns, MultiIndex): -->3781 existing_piece = self[key] 3782 if isinstance(existing_piece, DataFrame): 3783 value = np.tile(value, (len(existing_piece.columns), 1))PATH/frame.py in __getitem__(self, key) 2971 if self.columns.nlevels > 1: 2972 return self.getitem_multilevel(key) -->2973 return self.__get_item_cache(key_ 2974 2975 # Do we have a slicer (on rows)?
查看完整描述