天天看點

AssertionError: 618 columns passed, passed data had 508 columns【已解決】問題描述彎路解決方案

問題描述

程式中斷,報錯如下AssertionError: 618 columns passed, passed data had 508 columns

Exception has occurred: ValueError
618 columns passed, passed data had 508 columns
AssertionError: 618 columns passed, passed data had 508 columns

The above exception was the direct cause of the following exception:

  File "E:\matlab\CHB-MIT-DATA\epilepsy_eeg_classification\preprocessing.py", line 117, in eeg_preprocessing
    res = pd.DataFrame(res, columns=column_names)
  File "E:\matlab\CHB-MIT-DATA\epilepsy_eeg_classification\preprocessing.py", line 334, in <module>
    res = eeg_preprocessing(file, seizures)
ValueError: 618 columns passed, passed data had 508 columns
           
AssertionError: 618 columns passed, passed data had 508 columns【已解決】問題描述彎路解決方案

 terminal報錯如下:

Backend Qt5Agg is interactive backend. Turning interactive mode on.

AssertionError: 618 columns passed, passed data had 508 columns【已解決】問題描述彎路解決方案

彎路

numpy1.19.4改為了numpy1.21.6

pip list: numpy1.21.6

conda list: numpy1.20.1

發現,報錯仍舊一樣,沒有任何改變。

我的懷疑是資料裡面有nan值,而程式中并沒有處理的方法,是丢棄是補充為0還是補充為平均值。因為如果丢棄的話。

我發現numpy版本不對,解除安裝的時候,報錯說:

PackageNotInstalledError: Package is not installed in prefix
           

于是我使用

conda udate numpy

報錯如下:

(base) PS E:\matlab> conda update numpy
Collecting package metadata (repodata.json): done
Solving environment: -
The environment is inconsistent, please check the package plan carefully
The following packages are causing the inconsistency:

  - defaults/win-64::anaconda==custom=py37_1
  - https://repo.anaconda.com/pkgs/main/win-64::bkcharts==0.2=py37_0
  - https://repo.anaconda.com/pkgs/main/win-64::blaze==0.11.3=py37_0
  - https://repo.anaconda.com/pkgs/main/win-64::bokeh==0.13.0=py37_0
  - https://repo.anaconda.com/pkgs/main/win-64::dask==0.19.1=py37_0
  - https://repo.anaconda.com/pkgs/main/win-64::numpydoc==0.8.0=py37_0
  - https://repo.anaconda.com/pkgs/main/win-64::odo==0.5.1=py37_0
  - https://repo.anaconda.com/pkgs/main/win-64::seaborn==0.9.0=py37_0
  - https://repo.anaconda.com/pkgs/main/win-64::sphinx==1.7.9=py37_0
  - https://repo.anaconda.com/pkgs/main/win-64::spyder==3.3.1=py37_1
  - https://repo.anaconda.com/pkgs/main/win-64::statsmodels==0.9.0=py37h452e1ab_0
  - defaults/win-64::_anaconda_depends==5.3.1=py37_0
failed

CondaMemoryError: The conda process ran out of memory. Increase system memory and/or try again.
           

有人說可以直接退到base環境更新conda。

(base) PS E:\matlab> conda update --name base conda
Collecting package metadata (repodata.json): done
Solving environment: |
The environment is inconsistent, please check the package plan carefully
The following packages are causing the inconsistency:

  - defaults/win-64::anaconda==custom=py37_1
  - https://repo.anaconda.com/pkgs/main/win-64::bkcharts==0.2=py37_0
  - https://repo.anaconda.com/pkgs/main/win-64::blaze==0.11.3=py37_0
  - https://repo.anaconda.com/pkgs/main/win-64::bokeh==0.13.0=py37_0
  - https://repo.anaconda.com/pkgs/main/win-64::dask==0.19.1=py37_0
  - https://repo.anaconda.com/pkgs/main/win-64::numpydoc==0.8.0=py37_0
  - https://repo.anaconda.com/pkgs/main/win-64::odo==0.5.1=py37_0
  - https://repo.anaconda.com/pkgs/main/win-64::seaborn==0.9.0=py37_0
  - https://repo.anaconda.com/pkgs/main/win-64::sphinx==1.7.9=py37_0
  - https://repo.anaconda.com/pkgs/main/win-64::spyder==3.3.1=py37_1
  - https://repo.anaconda.com/pkgs/main/win-64::statsmodels==0.9.0=py37h452e1ab_0
  - defaults/win-64::_anaconda_depends==5.3.1=py37_0
failed

CondaMemoryError: The conda process ran out of memory. Increase system memory and/or try again.
           

conda update conda,conda update numpy,conda update --name base conda,在cat(自建虛拟環境)和base裡都報錯:

CondaMemoryError: The conda process ran out of memory. Increase system memory and/or try again.
           

還有的朋友建議:

conda update conda -c conda-canary
           

但是仍舊不行,報錯如下,和前面的報錯也一樣。 

AssertionError: 618 columns passed, passed data had 508 columns【已解決】問題描述彎路解決方案

CondaMemoryError:conda 程序記憶體不足答案 - 愛碼網

更新anaconda的版本也報同樣的錯:

(base) PS E:\matlab> conda update anaconda
Collecting package metadata (repodata.json): done
Solving environment: \
The environment is inconsistent, please check the package plan carefully
The following packages are causing the inconsistency:

  - defaults/win-64::anaconda==custom=py37_1
  - https://repo.anaconda.com/pkgs/main/win-64::bkcharts==0.2=py37_0
  - https://repo.anaconda.com/pkgs/main/win-64::blaze==0.11.3=py37_0
  - https://repo.anaconda.com/pkgs/main/win-64::bokeh==0.13.0=py37_0
  - https://repo.anaconda.com/pkgs/main/win-64::dask==0.19.1=py37_0
  - https://repo.anaconda.com/pkgs/main/win-64::numpydoc==0.8.0=py37_0
  - https://repo.anaconda.com/pkgs/main/win-64::odo==0.5.1=py37_0
  - https://repo.anaconda.com/pkgs/main/win-64::seaborn==0.9.0=py37_0
  - https://repo.anaconda.com/pkgs/main/win-64::sphinx==1.7.9=py37_0
  - https://repo.anaconda.com/pkgs/main/win-64::spyder==3.3.1=py37_1
  - https://repo.anaconda.com/pkgs/main/win-64::statsmodels==0.9.0=py37h452e1ab_0
  - defaults/win-64::_anaconda_depends==5.3.1=py37_0
failed

CondaMemoryError: The conda process ran out of memory. Increase system memory and/or try again.
           

找到好久找到了一個解決方案:

AssertionError: 618 columns passed, passed data had 508 columns【已解決】問題描述彎路解決方案

 https://github.com/conda/conda/issues/10751

解決方案

說到最後實在是稀松平常,我檢查了一下程式邏輯。我發現在傳遞參數的過程中。

  File "E:\matlab\CHB-MIT-DATA\epilepsy_eeg_classification\preprocessing.py", line 117, in eeg_preprocessing

    res = pd.DataFrame(res, columns=column_names)

  File "E:\matlab\CHB-MIT-DATA\epilepsy_eeg_classification\preprocessing.py", line 334, in <module>

雖然報錯在117處,但是,實際上在傳遞的這兩個資料處,通過debug的方式,發現擷取的資料的列數要大于實際列數。那是因為,信号的channel變化的,而不是23個固定不變的,是以,隻需要把這個固定的23改為,len(channel)就能擷取到具體的數字。

for i in range(23):
            features.extend(eeg_features(temp[i]).tolist())
           

改為

for i in range(len(channels)):
            features.extend(eeg_features(temp[i]).tolist())
           

即可。

需要特别說明的是,conda建立的虛拟環境不要胡亂删除,否則會報很多錯,你可以根據報錯内容删除一些相應的檔案,但是不能删除過多的檔案。否則會報無數的錯誤。

這會讓你非常頭疼。這三篇文章都是我删錯檔案報錯的。

AssertionError: 618 columns passed, passed data had 508 columns【已解決】問題描述彎路解決方案

 你會發現你無意中删除了一些包的依賴,這就麻煩了。

另外,我的程式報錯或許和你的雖然報錯一樣,但是具體錯誤的地方不一樣,這個時候,你就要好好檢查你生成的資料和列名是否符合情況。可以參考這篇文章來看看,或許能夠解決你的錯誤:

已解決ValueError: 4 columns passed, passed data had 2 columns_無 羨ღ的部落格-CSDN部落格

參考文章

Packagenotinstallederror:未安裝在字首中 - IT寶庫