matplotlib水平居中、垂直居中text
plt.text(x, y, 'string', ha='center', va='center')
word选中所有交叉引用
^19 REF _Ref^#^#^#^#^#^#^#^#^# \r \h
ImportError: cannot import name ‘PILLOW_VERSION’ from ‘PIL’
降低版本
pip install Pillow==6.2.2 --user
取消警告
import warnings
# 全部取消
warnings.filterwarnings("ignore")
# 部分取消
with warnings.catch_warnings():
warnings.simplefilter("ignore")
# your code
data[ : , -1] 与 data[ : , -1: ]的区别
前者是标量,后者是矩阵
补全、修复html不规范的标签
from bs4 import BeautifulSoup
raw_html ='<td\>示例</tr>'
soup = BeautifulSoup(raw_html ,'lxml')
fixed_html = soup.prettify()
print(fixed_html)
# '<html>\n <body>\n <td>\n 示例\n </td>\n </body>\n</html>'
CentOS7更改主机名
vi /etc/hostname
git命令行中文显示不正确
git config --global core.quotepath false
符合PEP的import规范
- python内置模块
- 第三方模块
- 本地模块
打包单个py文件
安装Pyinstaller
进入需要打包的文件目录
pyinstaller -Fw file.py
# -w 不显示终端
# -F 将所有的库打包成一个文件
pd.DataFrame.join遇到的坑
先看一下参数
举例
df = pd.DataFrame({'key': ['K0', 'K1', 'K2', 'K3', 'K4', 'K5'],
'A': ['A0', 'A1', 'A2', 'A3', 'A4', 'A5']})
other = pd.DataFrame({'key': ['K0', 'K1', 'K2'],
'B': ['B0', 'B1', 'B2']})
如果想要指定on='key’连接两表,下面这样写会报错
df.join(other, on='key')
这是因为,参数中的on默认是在df和other两个数据框的index上,如果指定on=‘key’,则指定的仅是df数据框,other数据框还是以index为基础。
所以应该写成:
df.join(other.set_index('key'), on='key')
MongoDB常规启动方式
mongod --dbpath E:\MongoDB\data
plt.rcParams.keys()查看全局设置参数
Pyecharts遇到的坑—Surface3D图画不出来
找不同:
::输入的data格式(x,y,z),y列先不变。。。
numpy、pandas设置保存小数点位数/不使用科学计数法
np.set_printoptions(suppress=True,precision=3) # 不使用用科学计数法,保留三位小数
pd.set_option('display.float_format',lambda x : '%.4f' % x) # 保留小数点后4位有效数字
matplotlib不正常显示中文或符号
plt.rcParams['font.family'] = ['sans-serif'] #显示中文标签
plt.rcParams['font.sans-serif']=['SimHei']
plt.rcParams['axes.unicode_minus']=False
DataFrame中列名最好不要单独使用数字,不然画图时有可能会出问题
pandas导入.mat文件
import pandas as pd
from scipy import io
dataset = scipy.io.loadmat('.mat文件路径')
data = dataset['数据名'] # 可以通过查看dataset获取数据名
dfdata = pd.DataFrame(data)
ERROR: Cannot find command ‘git’ - do you have ‘git’ installed and in your PATH?
执行命令:
conda install git
Markdown更改字体颜色
<font color=red>我是红色</font>
效果:我是红色
Seaborn无法正常显示中文
# 需要与画图命令放在一个Cell中
sns.set_style({'font.sans-serif':['simhei', 'Arial']})
更换pip源到国内镜像
pip install -i https://pypi.tuna.tsinghua.edu.cn/simple 库名
pip install -i https://pypi.douban.com/simple 库名
conda换源
-c https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main/
scrapy安装报错
找到对应版本下载
再执行下载命令
pip install L:\download\Twisted-20.3.0-cp38-cp38-win32.whl
install后跟完整路径
conda创建虚拟环境
在默认路径下创建:.\anaconda3\envs
conda create -n env_name python=3.6
删除虚拟环境
conda remove -n env_name --all
指定安装路径
conda create --prefix=L:\your\path python=3.6
删除指定路径下的虚拟环境
conda remove --prefix=L:\your\path --all
jupyter添加kernal
激活虚拟环境后执行
conda install nb_conda
pandas.DataFrame.iloc函数小细节
dataset.iloc[ : , : 1 ] # 返回一个多×1维的数组
dataset.iloc[ : , 0 ] # 返回一个一维数组
numpy拼接两矩阵
np.column_stack((a,b)) # 行数相同