Notes on Python
记录一些使用Python中出现的问题, 新特性, 或是一些奇技淫巧.
Anaconda
--prefix
- Target Environment Specification: Full path to environment location (i.e. prefix).
- 前缀;前置代号(置于前面的单词或字母、数字); <旧>(人名前的)称谓
- 在……前面加(字母或数字);加……作为前言(开场白)
1 | conda create -p syc_py39_pyt112_cuda113 python=3.9 |
--name
cannot be used with--prefix
– Thomas Fauskanger, how to specify new environment location for conda create
conda info --envs
shows blank for name but does show the full path- activating the environment necessitates that I type out the full path
– Joshua Zastrow, how to specify new environment location for conda create
更改安装目录
服务器的root
满了,
要把里面的anaconda3
整个搬到data
里, 详见Moving
Anacoda from install dir and changing $PATH doesn't work #270.
1 | sudo mkdir /data/anaconda3 |
Jupyter
- Working
with Jupyter notebook on a remote server:
ssh -N -f -L 8888:localhost:9000 fergus@funkyserver
对参数-N
,-f
和-L
的解释
Pandas
to_latex
pandas.io.formats.style.Styler.to_latex
1
2
3
4
5
6
7
8
9styler.to_latex(
buf='temp.tex',
caption="Selected stock correlation and simple statistics.",
clines="skip-last;data", # {"all;data", "all;index", "skip-last;data", "skip-last;index"}
convert_css=True,
position_float="centering", # {"centering", "raggedleft", "raggedright"}, optional
multicol_align="|c|", # {"r", "c", "l", "naive-l", "naive-r"}, optional
hrules=True,
)
column_format
The LaTeX column specification placed in location: \begin{tabular}{
} Defaults to ‘l’ for index and non-numeric data columns, and, for numeric data columns, to ‘r’ by default, or ‘S’ if
siunitx
isTrue
.注意不会判断LaTeX编译后是否报错
```python styler.to_latex(buf='temp.tex', column_format='llrrrrrrrrl', convert_css=True)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
| Value | Explaination | Example |
| :-----------: | :----------------------------------------------------------: | :-----------: |
| "llrrrrrrrrl" | (default) |  |
| "ll\|\|\|rr\|\|rr\|rrrr\|l" | With rules. ||
| "ll\|\|rr\|rr\|rrrr\|\|l" | With rules and`multicol_align=|c|`. |  |
### `hrules`
- Set to True to add \toprule, \midrule and \bottomrule from the {booktabs} LaTeX package. Defaults to `pandas.options.styler.latex.hrules`, which is False.
- ```python
styler.to_latex(buf='temp.tex', hrules=False, convert_css=True)Value Explanation Example False (default) True Add , and from the {booktabs} LaTeX package
clines
Use to control adding
\cline
commands for the index labels separation.- [生物]渐变群,生态群
```python styler.to_latex(buf='temp.tex', clines=None, convert_css=True)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
| Value | Explaination | Example |
| :---------------: | :----------------------------------------------------------: | :----------------------------------------------------------: |
| None | No cline commands are added. (default) |  |
| "all;data" | A cline is added for every index value extending the width of the table, including data entries. |  |
| "all;index" | As above with lines extending only the width of the index entries. |  |
| "skip-last;data" | A cline is added for each index value except the last level (which is never sparsified), extending the widtn of the table. |  |
| "skip-last;index" | As above with lines extending only the width of the index entries. |  |
### `multirow_align`
- If sparsifying hierarchical MultiIndexes whether to align text centrally, at the top or bottom using the multirow package. If not given defaults to `pandas.options.styler.latex.multirow_align`, which is “c”. **If “naive” is given renders without multirow.**
- ```python
styler.to_latex(buf='temp.tex', multirow_align='c', convert_css=True)Value Explanation Example "c" Center aligned. (default) "t" Top aligned. "b" Bottom aligned. "naive" Top aligned without multirow.
multicol_align
If sparsifying hierarchical MultiIndex columns whether to align text at the left, centrally, or at the right. If not given defaults to
pandas.options.styler.latex.multicol_align
, which is “r”. If a naive option is given renders without multicol. Pipe decorators can also be added to non-naive values to draw vertical rules, e.g. “|r” will draw a rule on the left side of right aligned merged cells.='temp.tex', multicol_align='r', convert_css=True) styler.to_latex(buf
Value Explanation Example "r" Right aligned. (default) "c" Center aligned. "l" Left aligned. "naive-r" Right aligned without multicol. "naive-l" Left aligned without multicol. "|r" Draw a rule on the left side of right aligned merged cells. "|c|" Draw rules on the both side of center aligned merged cells.
Troubleshooting
Ubuntu中安装包
Window里正常, 在Ubuntu配环境时发现, 在conda环境下使用pip安装, 需要选择pip, 完整的安装方法如下, 可参见Using Pip to install packages to Anaconda Environment:
- 使用
which -a pip
查看所有的pip路径, 使用which pip
查看当前的pip路径, 确定别装到别的环境里去了 - 安装包, 大致有三种方法
- 使用
/anaconda/envs/<EnvName>/bin/pip install <PackageName>
- 进入环境后
python -m pip install <PackageName>
,-m
的含义为module-name
, 见Meaning of python -m flag - 在Pycharm的Terminal里直接
pip install <PackageName>
- 使用
- 若发现环境还是装错位置了,
可能是使用了
--user
参数全局地安装了一些包, 要把他们都删了, 具体见local pip in conda environment checks globally and says Requirement already satisfied
Seaborn的安装
pip安装后报错load failed while importing _arpack: The specified procedure could not be found.
,
卸载后用conda安装就好了, 见Seaborn
ImportError: DLL load failed: The specified module could not be
found.