我写了一个Jupyter笔记本,现在它以某种方式转换为.py文件。 我想把它恢复成原始格式。 有人知道如何做吗?
之前有一个关于此的Stack Overflow问题,但解决方案对我不起作用。 将其转换为(而非从)IPython Notebook格式
以下是现在代码的示例。 它是很多代码,因此手动复制和粘贴需要花费数小时。
谢谢帮助。
{
"cell_type": "code",
"execution_count": 581,
"metadata": {},
"outputs": [],
"source": [
"def add_trig_slope(data, size = 1, axis = 0, option = 0, random = False, lower_b = -1, upper_b = 2): \n",
" \n",
" # To make the gradual decline of the fuck you plot\n",
" ## sin, cos, tan, sigmoid, other activation functions?\n",
" # need to list the option in the doc string\n",
" \n",
" ## Add a random element\n",
" newdata = data.copy()\n",
" cols = list(newdata.columns)\n",
" funcs = [math.sin, math.cos, math.tan, expit]\n",
" func = funcs[option]\n",
" if axis == 0:\n",
" for col in cols:\n",
" newdata.loc[:, col] -= size * (func(cols.index(col)))\n",
" if random:\n",
" newdata.loc[:,col] -= np.random.uniform(lower_b,upper_b)\n",
"\n",
" elif axis == 1:\n",
" for i, node in enumerate(newdata.index):\n",
" newdata.loc[node,:] -= size * (func(i))\n",
" if random:\n",
" newdata.loc[node,:] -= np.random.uniform(lower_b,upper_b)\n",
"\n",
" \n",
" return newdata\n",
" \n",
" "
]