Python
乱写乱画
一个用来记录笔记的博客
展开
-
langid 代码对应的语种名
langid 代码对应的语种名原创 2023-02-20 16:01:30 · 848 阅读 · 0 评论 -
pymysql sql语句中引号问题
【代码】pymysql sql语句中引号问题。原创 2022-09-28 11:42:33 · 314 阅读 · 0 评论 -
/backend_agg.py:238: RuntimeWarning: Glyph 26085 missing from current font.
linux 使用python matplotlib画图时没有字体显示中文,导致中文乱码 删除matplotlib字体缓存 rm -rf /home/ubuntu/.cache/matplotlib 然后在python中指定字体,即可正常显示中文原创 2022-06-09 15:05:07 · 1040 阅读 · 1 评论 -
Python3通过writerow写入csv文件 多了一条空行
1.声明csv.writer() 时 将dialect设置为unix,换行符即为'\n'with open(self.game_name + '2022.csv', 'w', encoding='utf-8-sig') as f: writer = csv.writer(f, dialect='unix') # 将dialect设置为unix,换行符即为'\n' writer.writerow(self.bilibili_columns)原创 2022-05-31 15:59:49 · 1255 阅读 · 0 评论 -
pymysql 重连
self.conn.ping(reconnect=True)原创 2021-11-01 10:23:29 · 748 阅读 · 0 评论 -
windows下python使用protobuf的开门级教程
转载自:https://blog.csdn.net/u013992365/article/details/81287041一、在windows下编译python所需的protobuf的相关文件1、首先下载protobuf源码(后一个是我自己从github上down的,因为版本是3.6.0,因为网不好下了很久,但是这个是完全体,就是我把包括python在内的全部版本都下了下来):https://github.com/google/protobuf/releases/tag/v3.6.0或是:http转载 2021-07-23 16:07:43 · 1058 阅读 · 2 评论 -
is not clickable at point (530, 16). Other element would receive the click
使用selenium发送点击请求报错翻译了一下不能点击,被其他元素接受了请求解决方法1button.send_keys("\n") #方法2from selenium.webdriver.common.keys import Keysbutton.send_keys(Keys.SPACE) #方法3driver.execute_script("arguments[0].click();", button)经过gen...原创 2021-06-15 17:07:33 · 255 阅读 · 0 评论 -
ValueError: check_hostname requires server_hostname
python3 爬取数据时报错requests.get("https://www.baidu.com/", proxies={'http': 'http://183.53.29.159:25862', 'https': 'https://183.53.29.159:25862'})原创 2021-06-10 15:46:28 · 167 阅读 · 0 评论 -
TypeError: __init__() takes 1 positional argument but 5 positional arguments (and 1 keyword-only arg
python脚本迁移时报错:TypeError: __init__() takes 1 positional argument but 5 positional arguments (and 1 keyword-only argument) were given原因:原创 2021-06-08 15:34:48 · 1373 阅读 · 1 评论 -
python 保留小数位数
a = 12.345a1 = round(a, 2)print(a1)原创 2021-04-22 11:05:20 · 193 阅读 · 0 评论 -
selenium.common.exceptions.WebDriverException: Message: unknown error: cannot find Chrome binary
http://npm.taobao.org/mirrors/chromedriver/89.0.4389.23/1,到这个地址下载浏览器对应的浏览器驱动2,将安装包解压代码指定驱动路径webdriver.Chrome(r'E:\ChromeDriver\chromedriver.exe', chrome_options=chrome_options)原创 2021-04-19 10:12:09 · 401 阅读 · 0 评论 -
selenium 自动下载对应Chrome版本
from webdriver_manager.chrome import ChromeDriverManagerbrowser = webdriver.Chrome(ChromeDriverManager().install())原创 2021-04-16 16:24:34 · 293 阅读 · 0 评论 -
python sorted 处理二维数组排序
>>> l = [[1, 2, 3], [2, 3, 4], [2, 1, 3]]>>> sorted(l, key=lambda l: l[1], reverse=True)[[2, 3, 4], [1, 2, 3], [2, 1, 3]]>>> sorted(l, key=lambda l: l[1])[[2, 1, 3], [1, 2, 3], [2, 3, 4]]原创 2021-03-17 14:42:15 · 3212 阅读 · 0 评论 -
pip install 安装第三方库报错SSL: CERTIFICATE_VERIFY_FAILED
bootstrap下载地址:https://v3.bootcss.com/getting-started/#download创建Django项目:django-admin startproject 项目名新建一个文件夹存储所有的APP mkdir APPS转载 2020-12-30 18:16:56 · 432 阅读 · 0 评论 -
python jsonpath与get 尝试获取json字符串中指定key
jsonpath:语法类似xpath,尝试指定范围获取所有符合条件的key,返回类型:listvalue 为json objimport jsonimport jsonpathjsonpath.jsonpath(value, "$..numComments")get 字典方法,尝试获取key,没有返回指定内容,默认为空>>> text = {"c":1, "a":1}>>> richtext2 = text.get('t', "")>&g.原创 2020-09-10 16:25:19 · 2285 阅读 · 1 评论 -
pandas数据处理--将txt中的数据进行去重统计数量
import pandas as pdimport numpy as npfrom openpyxl import load_workbookimport osimport reclass doWork: def __init__(self): self.txt_file_dir = "txt_file" self.excel_name1 = r"template.xlsx" # 模板文件 self.excel_name2 = r"sta.原创 2020-08-10 19:07:44 · 1286 阅读 · 0 评论 -
pandas 写入不同sheel
writer=pd.ExcelWriter('tarkov_market.xlsx') self.last_1_Y.to_excel(writer,sheet_name='last_1_M',index=0)#index=0:无索引 self.last_6_M.to_excel(writer,sheet_name='last_7_day',index=0) self.last_1_M.to_excel(writer,sheet_name='last_1_Y'.原创 2020-08-10 11:04:54 · 210 阅读 · 0 评论 -
Python 递归当前文件夹下的所有文件
def get_dir(code_file_dir): #获取目录路径 for root,dirs,files in os.walk(code_file_dir, followlinks=False): #遍历path,进入每个目录都调用visit函数,,有3个参数,root表示目录路径,dirs表示当前目录的目录名,files代表当前目录的文件名 print(root,dirs,files) for filename in files: f.原创 2020-08-10 10:25:48 · 316 阅读 · 0 评论 -
Python 报错重试 装饰器
def retry_on_failure(func): def wrapper(*args, **kwargs): flage = 0 while True: if flage >= 2: raise Exception('超过重试次数boom') try: return func(*args, **kwargs) excep.原创 2020-07-30 19:54:42 · 380 阅读 · 0 评论 -
Python 爬虫处理base64加密,解密方法
import base64import timectime = str(time.time())user_str = str({'user':user, 'user_type':user_type, 'user_id':user_id})# 加密token = base64.b64encode(user_str.encode(encoding='utf-8')).decode()# 解密user_str = base64.b64decode(token.encode(encoding='u.原创 2020-07-28 09:47:58 · 1416 阅读 · 1 评论 -
pandas 将两数据表进行拼接
将两文本内容以下图为例合并,空值补0:import pandas as pddef go(path1, path2, new_file_name): df1 = pd.read_csv(path1, encoding="utf-8") df2 = pd.read_csv(path2, encoding="utf-8") columns = df1.columns df_obj = pd.concat([df1,df2], sort=False) ..原创 2020-07-24 15:55:33 · 563 阅读 · 0 评论 -
Python 队列生产者,消费者模型
In [1]: from queue import Queue ...: ...: import random ...: ...: import threading ...: ...: import timeIn [3]: class Producer(threading.Thread): ...: def __init__(self, t_name, queue): ...: threading.Thread.__init__(.原创 2020-07-17 10:41:23 · 176 阅读 · 0 评论 -
Python No module named ‘sklearn.cross_validation‘
sklearn中已经废弃cross_validation,将其中的内容整合到model_selection中 将sklearn.cross_validation 替换为 sklearn.model_selection原创 2020-07-14 16:53:04 · 157 阅读 · 0 评论 -
python字典自定义排序,使用匿名函数根据字典value大小排序
d= {'a':24,'g':52,'i':12,'k':33}sorted(d.items(), key=lambda x : x[1], reverse=True)# d.items() 字典items将字典变为(key,value)的元组对象# key 自定义排序规则# reverse 是否倒序原创 2020-07-07 16:07:29 · 658 阅读 · 0 评论 -
python 数据写入json文件时中文显示Unicode编码问题
使用:json加载时数据出现Unicodereturn json.dumps(content)输出:{"Harris HBR Bipod": {"description": "Harris HBR ultralight foldable bipod with spring retraction mechanism. Used across the world by service operators and civilian shooters worldwide.\n", "General原创 2020-06-29 16:09:21 · 4067 阅读 · 0 评论 -
python 数据处理时去除emoji表情
方法一:emoji处理库,emoji官网:https://pypi.org/project/emoji/#安装 pip install emoji官方例子如下:清除命令:emoji.demojize(str)方法二:def filter_emoji(desstr,restr=''): #过滤表情 try: co = re.compile(u'[\U00010000-\U0010ffff]') except ..原创 2020-05-27 11:27:28 · 2429 阅读 · 0 评论 -
pymysql 将图片存入MySQL
帮忙写了个MySQL存储图片的脚本,在这留个记录MySQL建表语句:CREATE TABLE `image` ( `image_name` varchar(255) NOT NULL COMMENT '图片名', `game_name` varchar(255) NOT NULL COMMENT '图片所属游戏', `id` int NOT NULL AUTO_INCREMENT COMMENT '自增主键', `image` mediumblob COMMENT '图片内容',.原创 2020-05-21 16:38:36 · 1387 阅读 · 0 评论 -
python将中文字符转为浏览器传输格式%20,%3A
import urllib.parse as parseres = parse.quote("lang:ja until:2020-05-07 since:2020-05-06 ナルト", encoding="UTF-8")res'lang%3Aja%20until%3A2020-05-07%20since%3A2020-05-06%20%E3%83%8A%E3%83%AB%E3%83%88'res = parse.unquote('lang%3Aja%20until%3A2020-05-07%2.原创 2020-05-20 15:22:00 · 1390 阅读 · 0 评论 -
BeautifulSoup正则匹配
div_list = soup_obj.find_all("div", {"data-testid": re.compile(r"position: absolute;.*?;")})原创 2020-05-20 10:57:50 · 726 阅读 · 0 评论 -
pymysql创建游标,返回数据为字典类型
cursor = conn.cursor(cursor=pymysql.cursors.DictCursor) # 获取字典类型数据原创 2020-05-06 16:09:58 · 1333 阅读 · 0 评论 -
python 多线程读写MySQL
import pymysqlimport threadingimport datetimeimport randomimport requestsimport jsonimport reimport timeclass DB(object): """创建MySQL实例""" def __init__(self, host=None, username=None,...原创 2020-04-30 15:56:31 · 1207 阅读 · 0 评论 -
Python jieba分词使用方法记录
方法说明:jieba.cut 方法接受三个输入参数: 需要分词的字符串;cut_all 参数用来控制是否采用全模式;HMM 参数用来控制是否使用 HMM 模型 jieba.cut_for_search 方法接受两个参数:需要分词的字符串;是否使用 HMM 模型。该方法适合用于搜索引擎构建倒排索引的分词,粒度比较细,待分词的字符串可以是 unicode 或 UTF-8 字符串、GBK 字符串。...原创 2020-04-27 18:42:45 · 442 阅读 · 0 评论 -
Python 日期加减一天
import datetimestr(datetime.date.today() + datetime.timedelta(days=-1))原创 2020-04-24 14:51:36 · 764 阅读 · 0 评论 -
django.core.exceptions.ImproperlyConfigured: mysqlclient 1.3.13 or newer is required; you have 0.9.3
使用Django连接MySQL报错: raise ImproperlyConfigured('mysqlclient 1.3.13 or newer is required; you have %s.' % Database.__version__)django.core.exceptions.ImproperlyConfigured: mysqlclient 1.3.13 or ne...原创 2020-01-21 14:26:23 · 269 阅读 · 0 评论 -
将数字时间转为日期
import datetimedatetime.datetime.fromtimestamp(1578141805)datetime.datetime(2020, 1, 4, 20, 43, 25)datetime.datetime.fromtimestamp(1577992610).strftime("%Y-%m-%d %H:%M:%S")'2020-01-03 03:16:50'...原创 2020-01-07 10:56:41 · 939 阅读 · 0 评论 -
Python操作CSV文件
# 读取CSV文件import csvcsvFile = open(r'C:\Users\xufan\Downloads\data-text.csv', 'r')contant = csv.DictReader(csvFile)# 以字典键值对形式读取,键为CSV 文件的第一行for line in contant: print(line) print(line...原创 2019-09-03 16:16:05 · 189 阅读 · 0 评论 -
pip离线安装Python依赖包
新建一个文件夹,并将Python包和依赖下载到文件夹中:# cd /tmp# mkdir pandas# pip install --download /tmp/pandas pandas# tar zcvf pandas.tar.gz /tmp/pandas将打包好的压缩包上传到目标服务器解压安装:# cd /tmp# tar zxvf pandas.tar.gz...原创 2019-09-03 15:05:16 · 530 阅读 · 0 评论 -
Python练习之数组排序
选择排序def findSmallIndex(array): smallData = array[0] smallDataIndex = 0 for index in range(1, len(array)): if smallData > array[index]: smallData = array[index] ...原创 2019-08-30 09:59:14 · 193 阅读 · 0 评论 -
Python复习之matplotlib简单练习
# coding:utf8import matplotlib.pyplot as pltimport numpy as npdef line_chart(): # 保存X轴数据的列表 x_values = [x for x in range(1,11)] # 保存y轴数据的列表 y_values = [x ** 2 for x in range(1, 11...原创 2019-08-29 15:21:12 · 238 阅读 · 0 评论 -
Python复习之Counter,heapq、itertools等的用法
"""找出序列中出现次数最多的元素"""from collections import Counterwords = [ 'look', 'into', 'my', 'eyes', 'look', 'into', 'my', 'eyes', 'the', 'eyes', 'the', 'eyes', 'the', 'eyes', 'not', 'around', ...原创 2019-08-27 15:38:03 · 246 阅读 · 0 评论
分享