随笔分类 - python
摘要:#解决方案 把 …\anaconda3\Library\bin 加入到系统环境变量即可。总是提示SSL有问题,然而只是SSL就在bin里边,所以没有生效。主要参考:https://github.com/conda/conda/issues/6064感谢github,中文的社区都搜遍了了,全是linu
阅读全文
摘要:1. 选择除了其中一行的所有行 import pandas as pd import numpy as np df = pd.DataFrame(np.random.rand(8,4),columns=['a','b','c','d']) df df.loc[:,df.columns !='d']
阅读全文
摘要:1. 准备慢日志的csv文件 import pandas as pd import matplotlib.pyplot as plt # 选取耗时大于7000的日志 # awk -F '耗时:' '{if (int(substr($2,0,length($2)-2)) >7000) print $0
阅读全文
摘要:2.1 在绘图代码中设置全局字体 from pylab import mpl # 设置显示中文字体 mpl.rcParams["font.sans-serif"] = ["SimHei"] 使用matplotlib绘图中文字符显示问题:UserWarning: missing from curren
阅读全文
摘要:1.报表模板 #cat xunjian_table.html [root@yinliao-yanshi report_jinja2]# cat xunjian_table.html <html> <head> <meta http-equiv="Content-Type" content="text
阅读全文
摘要:1. 读取excel文件。由列变成行。每个item是一个字典 import pandas as pd from jinja2 import Environment, FileSystemLoader df = pd.read_excel('回测指标汇总.xlsx') df['消耗本金'] = df[
阅读全文
摘要:python3安装后’yum’命令执行会报错,需要修改以下配置: /usr/bin/yum: 将文件第一行改为/usr/bin/python2.7。(2.7.x也改为2.7)/usr/libexec/urlgrabber-ext-down: 将文件第一行改为/usr/bin/python2.7。 参
阅读全文
摘要:1. 导入数据 import pandas as pd #导入Pandas df_sales_02 = pd.read_csv('订单记录.csv') #载入数据 df_sales_02.head() #显示头几行数据 2. 数据可视化 import matplotlib.pyplot as plt
阅读全文
摘要:1. 利用loc、iloc提取行数据 import numpy as np import pandas as pd #创建一个Dataframe data=pd.DataFrame(np.arange(16).reshape(4,4),index=list('abcd'),columns=list(
阅读全文
摘要:1. 环境Windows10,python3.8,pillow8.4.0 2. 换成python3.8 conda create --name wincoda0226py38 python=3.8 (wincoda0226py38) D:\Users\linux\Desktop>pip instal
阅读全文
摘要:1. pytorch 训练模型的时候报错 “RuntimeError: DataLoader worker (pid 83709) is killed by signal: Bus error. It is possible that dataloader’s workers are out of
阅读全文
摘要:1. 首先,你会发现,相对位置是一种很不好的选择。因为代码可能会迁移,相对位置会使得重构既不雅观,也易出错。因此,在大型工程中尽可能使用绝对位置是第一要义。对于一个独立的项目,所有的模块的追寻方式,最好从项目的根目录开始追溯,这叫做相对的绝对路径。 2. 例子 3. 原理 export PYTHON
阅读全文
摘要:1. Python Celery 快速实现分布式的任务队列管理 (toutiao.com) 2. Python编程:Celery执行异步任务和定时任务-阿里云开发者社区 (aliyun.com)
阅读全文
摘要:1. 10秒钟测试ip段所有IP的连通性 (base) [root@wlt-overseas-middleware-master ~]# cat su-asyncio-re-cancel.py import asyncio import time import re # call shell cmd
阅读全文
摘要:1. asyncio import time import asyncio # func called as one task async def worker_1(time_sleep): print('worker_1 had been called') await asyncio.sleep(
阅读全文
摘要:1. 要解决的问题: 想要快速的访问类中的私有属性,但是不想直接暴露出原来类中的属性 @property def tick(self): return self._tick 2. 经典例子 # property decorator make defining and modifying class'
阅读全文
摘要:1.先定义生成器 2.用next(generator)调用生成器,相加,验证 # todo: define my_generater and be called by next() def my_generater(k): i = 1 while True: yield i ** k i += 1
阅读全文
摘要:1.问题: 在[1, 2, 3, 4, 5, 6]中,找出满足 x*x > target的最小的数; 2. l r mid array[mid] flag(指针) target 0 5 2 9 -1 15 3 5 4 25 4 15 3 3 3 16 3 15 3.代码 # [1, 2, 3, 4,
阅读全文
摘要:1.函数 import sys class Callcount01: def __init__(self, func): self.func = func self.call_num = 0 def __call__(self, *args, **kwargs): self.call_num +=
阅读全文
摘要:1.有个坑 re.sub('[^\w]', ' ', 'hello world, get rid of comma') --> [^\w] 非字符的意思 [^abc] 匹配除了a,b,c之外的字符 import re text_string = re.sub(r'([^\s\w]|_|[0-9])+
阅读全文