遇到同样问题的朋友,请直接看下面已经跑通的代码:
%%writefile read_datasets.py
#一、读取达观杯竞赛数据
import pandas as pd
def read_DC_dataset(filename,index):
dataset=pd.read_csv(filename,header=0,index_col=index)
return dataset.head()
print(read_DC_dataset('train_set.csv',index='id'))
运行结果如下:
Writing read_datasets.py
jupyter notbook 魔法代码:
%%writefile filename
上面这行代码必须写在代码的最前面一行,否则返回如下错误:
UsageError: Line magic function `%%writefile` not found.