python - 从同一笔记本导入表

标签 python powershell jupyter-notebook markdown azure-data-studio

如何从文本 block 中读取 Markdown 表并导入到同一 PowerShell 笔记本中代码块中的变量中?

尝试使用 PowerShell 导入

$b=Import-Csv -Path <> -Delimiter '|'

enter image description here

无法弄清楚如何指向 -Path同一笔记本中文本 block 的参数。在 Azure Data Studio 中使用 .ipynb 文件。

最佳答案

我相信您正在寻找的功能是不可能的。作为解决方法,我建议首先将单元格 Markdown 存储为 Python 中的变量,然后使用该变量填充打印的 Markdown 单元格。这是一个例子。我相信它适用于任何基于 iPython 构建的笔记本:

#running this cell in your notebook will print the variable as Markdown
mymd = "# Some markdown"
from IPython.display import display, Markdown
display(Markdown(mymd))

更新:如果您担心表示多行 Markdown 太复杂,您有两个不错的选择。首先,使用三引号将换行符读取为字符串的一部分:

mymd = """
| First Header  | Second Header |
| ------------- | ------------- |
| Content Cell  | Content Cell  |
| Content Cell  | Content Cell  |
"""

选项 2:将 Markdown 放入文件中并将其读取为字符串:

with open("somefile.md") as f:
    mymd = f.read()

任一选项都会受益于记录良好且严格遵循的工作流程,但对于此用例来说效果很好。

关于python - 从同一笔记本导入表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60264332/

相关文章:

python - 想要从输出中获得最大值并将其应用到方程中

python - 从 subprocess.communicate() 读取流输入

python - discord.py ffmpeg 歌曲一开始播放太快

python - scikit 学习中断 pandas 安装

powershell - 将 powershell 控制台窗口移动到屏幕左侧的最佳方法是什么?

python - latex jupyter 笔记本不起作用

python - 如何打印最后一次出现的字符串加上后面的 N 行

powershell - 组织 PowerShell Cmdlet 类

powershell - Powershell中不带扩展名的文件输出

python - 使用 Python tensorflow 进行预测和预测