neuropsychology / NeuroKit

NeuroKit2: The Python Toolbox for Neurophysiological Signal Processing
https://neuropsychology.github.io/NeuroKit
MIT License
1.58k stars 421 forks source link

Error while creating html report with eda_process: 'charmap' codec can't encode character #977

Open caisdosodre opened 7 months ago

caisdosodre commented 7 months ago

Describe the bug My code is below:

import neurokit2 as nk
import pandas as pd
data1=pd.read_csv("sample.csv", names=["EDA"])
signals, info = nk.eda_process(data1["EDA"], sampling_rate=100, report="report.html")

Output:

The raw signal, sampled at 100 Hz, was cleaned using the default method of the neurokit2 package.

The signal was decomposed into phasic and tonic components using the method described in neurokit.

The cleaned signal was used to detect peaks using the default method of the `neurokit2` package.

References
- https://doi.org/10.21105/joss.01667
The report has been saved to report.html
---------------------------------------------------------------------------
UnicodeEncodeError                        Traceback (most recent call last)
Cell In[23], [line 1](vscode-notebook-cell:?execution_count=23&line=1)
----> [1](vscode-notebook-cell:?execution_count=23&line=1) signals, info = nk.eda_process(data1["EDA"], sampling_rate=100, report="report.html")

File [c:\Python312\Lib\site-packages\neurokit2\eda\eda_process.py:134](file:///C:/Python312/Lib/site-packages/neurokit2/eda/eda_process.py:134), in eda_process(eda_signal, sampling_rate, method, report, **kwargs)
    [132](file:///C:/Python312/Lib/site-packages/neurokit2/eda/eda_process.py:132)     else:
    [133](file:///C:/Python312/Lib/site-packages/neurokit2/eda/eda_process.py:133)         fig = None
--> [134](file:///C:/Python312/Lib/site-packages/neurokit2/eda/eda_process.py:134)     create_report(file=report, signals=signals, info=methods, fig=fig)
    [136](file:///C:/Python312/Lib/site-packages/neurokit2/eda/eda_process.py:136) return signals, info

File [c:\Python312\Lib\site-packages\neurokit2\misc\report.py:71](file:///C:/Python312/Lib/site-packages/neurokit2/misc/report.py:71), in create_report(file, signals, info, fig)
     [69](file:///C:/Python312/Lib/site-packages/neurokit2/misc/report.py:69) print(f"The report has been saved to {file}")
     [70](file:///C:/Python312/Lib/site-packages/neurokit2/misc/report.py:70) contents = [description, table_html, fig_html, ref]
---> [71](file:///C:/Python312/Lib/site-packages/neurokit2/misc/report.py:71) html_save(contents=contents, file=file)

File [c:\Python312\Lib\site-packages\neurokit2\misc\report.py:181](file:///C:/Python312/Lib/site-packages/neurokit2/misc/report.py:181), in html_save(contents, file)
    [178](file:///C:/Python312/Lib/site-packages/neurokit2/misc/report.py:178)     else:
    [179](file:///C:/Python312/Lib/site-packages/neurokit2/misc/report.py:179)         # assume the content is an interactive plotly figure and export to HTML
    [180](file:///C:/Python312/Lib/site-packages/neurokit2/misc/report.py:180)         inner_html = content.to_html().split("<body>")[1].split("</body>")[0]
--> [181](file:///C:/Python312/Lib/site-packages/neurokit2/misc/report.py:181)     page.write(inner_html)
    [182](file:///C:/Python312/Lib/site-packages/neurokit2/misc/report.py:182)     page.write("<br>")
    [183](file:///C:/Python312/Lib/site-packages/neurokit2/misc/report.py:183) page.write("</body></html>" + "\n")

File [c:\Python312\Lib\encodings\cp1252.py:19](file:///C:/Python312/Lib/encodings/cp1252.py:19), in IncrementalEncoder.encode(self, input, final)
     [18](file:///C:/Python312/Lib/encodings/cp1252.py:18) def encode(self, input, final=False):
---> [19](file:///C:/Python312/Lib/encodings/cp1252.py:19)     return codecs.charmap_encode(input,self.errors,encoding_table)[0]

UnicodeEncodeError: 'charmap' codec can't encode character '\u25c4' in position 291500: character maps to <undefined>

Expected behaviour HTML report output

Screenshots same as output

System Specifications

It's important that you give us some information about the system you are using. For that you can run:

import neurokit2 as nk
nk.version()

Running on ipynb notebook in VSCode