python填坑系列之jupyter notebook将代码保存为py文件
写在前面遇到同样问题的朋友,请直接看下面已经跑通的代码:%%writefile read_datasets.py#一、读取达观杯竞赛数据import pandas as pddef read_DC_dataset(filename,index):dataset=pd.read_csv(filename,header=0,index_col=index)return ...
·
遇到同样问题的朋友,请直接看下面已经跑通的代码:
%%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.
更多推荐

所有评论(0)