在emacs的组织模式下学习熊猫时,尝试了以下代码:
scientists = pd.DataFrame(
data={'Occupation': ['Chemist', 'Statistician'],
'Born': ['1920-07-25', '1876-06-13'],
'Died': ['1958-04-16', '1937-10-16'],
'Age': [37, 61]},
index=['Rosaline Franklin', 'William Gosset'],
columns=['Occupation', 'Born', 'Died', 'Age'])
print(scientists)
Jupyter制作
不幸的是,组织的babel不会产生非常漂亮的格式
标题未放在正确的列中。
如何改进格式?
答案 0 :(得分:0)
以下组织文件可以在AFAICT上完美运行:
* pandas
#+begin_src python :results output
import pandas as pd
scientists = pd.DataFrame(
data={'Occupation': ['Chemist', 'Statistician'],
'Born': ['1920-07-25', '1876-06-13'],
'Died': ['1958-04-16', '1937-10-16'],
'Age': [37, 61]},
index=['Rosaline Franklin', 'William Gosset'],
columns=['Occupation', 'Born', 'Died', 'Age'])
print(scientists)
#+end_src
#+RESULTS:
: Occupation Born Died Age
: Rosaline Franklin Chemist 1920-07-25 1958-04-16 37
: William Gosset Statistician 1876-06-13 1937-10-16 61
组织模式版本为Org mode version 9.2.3 (release_9.2.3-367-gd79e80)
编辑:我猜想罪魁祸首是:session
。似乎存在一个错误,即在复制输出时它会丢弃一行的初始空格。我在会话缓冲区中获取此信息:
Python 3.7.3 (default, May 11 2019, 00:45:16)
[GCC 8.3.1 20190223 (Red Hat 8.3.1-2)] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>>
'org_babel_python_eoe'
Occupation Born Died Age
Rosaline Franklin Chemist 1920-07-25 1958-04-16 37
William Gosset Statistician 1876-06-13 1937-10-16 61
>>> >>> >>> >>> 'org_babel_python_eoe'
>>>
但是组织缓冲区中的结果是:
#+RESULTS:
: Python 3.7.3 (default, May 11 2019, 00:45:16)
: [GCC 8.3.1 20190223 (Red Hat 8.3.1-2)] on linux
: Type "help", "copyright", "credits" or "license" for more information.
: Occupation Born Died Age
: Rosaline Franklin Chemist 1920-07-25 1958-04-16 37
: William Gosset Statistician 1876-06-13 1937-10-16 61
除了无法正确过滤掉多余的垃圾(可能是我的错误设置所致)之外,标头前面的初始空间也已完全消失。