Jupyter:找不到行魔术功能

Ale*_*lov 1 python jupyter-notebook

我有一个持续的错误:

%%writefile csvmagic.py
import pandas as pd
from io import StringIO

def csv(line, cell):
    sio = StringIO(cell)
    return pd.read_csv(sio)

def load_ipython_extension(ipython):
    """This function is called when the extension is
    loaded. It accepts an IPython InteractiveShell
    instance. We can register the magic with the
    `register_magic_function` method of the shell
    instance."""
    ipython.register_magic_function(csv, 'cell')

Overwriting csvmagic.py



%reload_ext csvmagic
%%csv
col1,col2,col3
0,1,2
3,4,5
7,8,9

UsageError: Line magic function `%%csv` not found.
Run Code Online (Sandbox Code Playgroud)

线魔法”在我看来不太合适,但我想不通。

来源在这里

Rol*_*ber 5

Afaik,您必须在单元格的开头放置单元格魔法。但是,%%csv在您的代码块内。确保以 开头的部分%%csv位于其自己的单元格中。否则,应该是细胞魔法的东西将被解释为线魔法。