ipynb.fs.full.<filename>: UnicodeDecodeError: 'charmap' codec can't decode byte 0x9d in position 32403: character maps to <undefined>

时间:2021-04-02 11:37:56

标签: python python-3.x unicode decoding

我正在尝试导入保存在 Jupyter Notebook 上另一个 python 文件中的函数。我收到以下错误:

UnicodeDecodeError: 'charmap' codec can't decode byte 0x9d in position 32403: character maps to <undefined>

同样,

ImportError: Could not import [...].ipynb for ipynb.fs.full.functions: not a valid ipynb file

我缩小了函数的范围,并强烈假设错误来自两个使用诸如 ' 或 ” 等字符的函数。这些字符很重要,因为函数应该清理文本并且这些字符出现在文本中。

示例函数:

def stopwords(own, save=False):
    stop = stopwords.words('english')
    stop_np = []
    for i in range(len(stop)):
        stop_np.append(stop[i].replace('’',"'").translate(str.maketrans('', '', string.punctuation)))
    append = own
    for i in range(len(append)):
        stop_np.append(append[i])
    if save==True:
        pd.DataFrame(sorted(stop_np)).to_csv(directory + 'stop.csv')

如何用 ipynb 导入这样的函数?

0 个答案:

没有答案