클러스터링 에러입니다. 도와주시면 감사하겠습니다...ㅠ_ㅠ
조회수 473회
전기사용량의 데이터(CSV, 사용량이 숫자로 표현됨)를 클러스터링 하는 과정에서 아래의 에러가 납니다. 축설정을 잘못한 것으로 보입니다. 바쁘신 와중에 답변해주신다면 정말 감사드리겠습니다ㅠ
이러한 형식의 파일을 파이썬으로 분석하여 클러스터링 시각화하려고 합니다...
df = pd.read_csv("LD2011_2014_copy3.csv") #load the dataset df.drop('date',axis=1,inplace=True) # Se elimina la columna no requerida
NameError Traceback (most recent call last) in ----> 1 df = pd.read_csv("LD2011_2014_copy3.csv") #load the dataset 2 df.drop('date',axis=1,inplace=True) # Se elimina la columna no requerida
NameError: name 'pd' is not defined
아래의 스크립트에서는 제목 등을 첨부하려고 했습니다만, 역시 오류가 납니다.Change categorical data to number 0-2
df["Electronic consumption"] = pd.Categorical(df["Electronic consumption"]) df["Electronic consumption"] = df["Electronic consumption"].cat.codes
Change dataframe to numpy matrix
data = df.values[:, 0:4] category = df.values[:, 4]
KeyError Traceback (most recent call last) ~\anaconda3\lib\site-packages\pandas\core\indexes\base.py in get_loc(self, key, method, tolerance) 2645 try: -> 2646 return self._engine.get_loc(key) 2647 except KeyError:
pandas_libs\index.pyx in pandas._libs.index.IndexEngine.get_loc()
pandas_libs\index.pyx in pandas._libs.index.IndexEngine.get_loc()
pandas_libs\hashtable_class_helper.pxi in pandas._libs.hashtable.PyObjectHashTable.get_item()
pandas_libs\hashtable_class_helper.pxi in pandas._libs.hashtable.PyObjectHashTable.get_item()
KeyError: 'Electronic consumption'
During handling of the above exception, another exception occurred:
KeyError Traceback (most recent call last) in 1 # Change categorical data to number 0-2 ----> 2 df["Electronic consumption"] = pd.Categorical(df["Electronic consumption"]) 3 df["Electronic consumption"] = df["Electronic consumption"].cat.codes 4 # Change dataframe to numpy matrix 5 data = df.values[:, 0:4]
~\anaconda3\lib\site-packages\pandas\core\frame.py in getitem(self, key) 2798 if self.columns.nlevels > 1: 2799 return self._getitem_multilevel(key) -> 2800 indexer = self.columns.get_loc(key) 2801 if is_integer(indexer): 2802 indexer = [indexer]
~\anaconda3\lib\site-packages\pandas\core\indexes\base.py in get_loc(self, key, method, tolerance) 2646 return self._engine.get_loc(key) 2647 except KeyError: -> 2648 return self._engine.get_loc(self._maybe_cast_indexer(key)) 2649 indexer = self.get_indexer([key], method=method, tolerance=tolerance) 2650 if indexer.ndim > 1 or indexer.size > 1:
pandas_libs\index.pyx in pandas._libs.index.IndexEngine.get_loc()
pandas_libs\index.pyx in pandas._libs.index.IndexEngine.get_loc()
pandas_libs\hashtable_class_helper.pxi in pandas._libs.hashtable.PyObjectHashTable.get_item()
pandas_libs\hashtable_class_helper.pxi in pandas._libs.hashtable.PyObjectHashTable.get_item()
KeyError: 'Electronic consumption'
-
(•́ ✖ •̀)
알 수 없는 사용자
댓글 입력