python
Miss_Audrey
宝剑锋从磨砺出,梅花香自苦寒来
展开
-
学习记录--生成微信url schema
学习记录URL Scheme原创 2022-08-31 16:59:38 · 805 阅读 · 0 评论 -
Pandas Shift函数(错位相加减)
Pandas Shift函数基础官方帮助文档如下:>>> import pandas>>> help(pandas.DataFrame.shift)Help on function shift in module pandas.core.frame: shift(self, periods=1, freq=None, axis=0) Shift index by desired number of periods with an optional time原创 2021-05-27 18:32:22 · 4388 阅读 · 1 评论 -
excel解密
import osimport pdfplumberimport refrom langconv import *import pymysqlfrom PyPDF2 import PdfFileReaderfrom PyPDF2 import PdfFileWriterimport datetimeimport eventletfrom multiprocessing import Process, Queue, Pooldef get_reader(filename, passwor原创 2020-09-10 09:33:56 · 581 阅读 · 0 评论 -
pandas工作学习笔记
# 检测字符串是否有中文def check_contain_chinese(check_str): for ch in check_str: if u'\u4e00' <= ch <= u'\u9fff': return True return Falsedef url_get_value(n_url): requests.adapters.DEFAULT_RETRIES = 5 s = requests.sessio原创 2020-09-10 09:16:34 · 155 阅读 · 0 评论 -
文字或词汇计数
from sqlalchemy import create_engineimport pandas as pd'''统计四字公司简称中前两个字中每个字'''con = create_engine('mysql+pymysql://user:password@host:3306/DB?charset=utf8')sql = 'sql查询语句'cur = con.execute(sql)res = cur.fetchall()print(len(res))li = []for i in原创 2020-09-09 17:50:57 · 166 阅读 · 0 评论 -
reduce与chain函数用法
reduce() 函数会对参数序列中元素进行累积。chain()函数将多个迭代器组合为单个迭代器from functools import reducefrom itertools import chaindict1 = {"a":1, "b":2, "c":3}dict2 = {"d":4, "e":5, "f":6}my_list = [dict1, dict2]li = [d.values() for d in my_list]print(li)print(reduce(chain原创 2020-09-09 17:34:14 · 277 阅读 · 0 评论 -
python发送邮件
# !/usr/bin/env python3# -*- coding: utf-8 -*-import smtplibfrom email.mime.text import MIMETextfrom email.utils import formataddr# 发件人邮箱账号my_sender = 'xxx@xxx.com'# user登录邮箱的用户名,password登录邮箱的密码(授权码,即客户端密码,非网页版登录密码),但用腾讯邮箱的登录密码也能登录成功my_pass = 'xx原创 2020-09-09 09:49:39 · 278 阅读 · 0 评论 -
python 字典根据value值排序
from collections import OrderedDictdic = {'a': 2, 'b': 5, 'c': 4, 'd': 1, 'e': 3}new_dic = OrderedDict(sorted(dic.items(), key=lambda kv: kv[1], reverse=True))last_dic = {item[0]: item[1] for item in new_dic.items()}# 结果:{'b': 5, 'c': 4, 'e': 3, 'a':原创 2020-08-13 17:39:13 · 402 阅读 · 0 评论 -
pandas读写数据同一张表不同的sheet
writer = pd.ExcelWriter(‘tb1.xlsx’)df1.to_excel(writer,“sheet1”)df2.to_excel(writer,“sheet2”)df3.to_excel(writer,“sheet3”)writer.save()原创 2020-08-13 15:50:37 · 1028 阅读 · 0 评论 -
Dataframe转化为字典格式的两种方法
df = df.to_dict(orient=‘records’)df = df.to_json(orient=‘records’)原创 2020-08-12 15:14:54 · 2926 阅读 · 0 评论 -
Python同时替换多个字符串
class make_xlat: def __init__(self, *args, **kwargs): self.adict = dict(*args, **kwargs) self.rx = self.make_rx() def make_rx(self): return re.compile('|'.join(map(re....原创 2020-05-06 16:11:28 · 673 阅读 · 0 评论 -
批量读取DataFrame内容
con = create_engine('mysql+pymysql://user:password@host:3306/database?charset=utf8')sql = '查询语句'cursor = con.execute(sql)res = cursor.fetchone()dfs = pd.read_sql(sql, con, chunksize=100000)for df...原创 2020-05-06 15:53:45 · 573 阅读 · 0 评论 -
python给excel单元格中的某些词汇或字符设置指定颜色
import xlsxwriterimport pandas as pdimport redef deal_cell_words(row, column, phrase, red, pattern, worksheet1): red_keywords = re.findall(pattern, phrase) print(red_keywords) if red_k...原创 2020-05-06 15:48:53 · 5701 阅读 · 0 评论 -
excel表拆分与加密
excel表拆分,由一张表拆分成多张表,表头字段一样# -*- coding:utf-8 -*-import osimport pandas as pdfrom sqlalchemy import create_engineimport xlrdfrom xlsxwriter.workbook import Workbookdef excel_split(): con =...原创 2020-05-06 11:34:23 · 615 阅读 · 1 评论 -
excel表合并(笔记)
import osimport pandas as pdimport xlrdimport tracebackrootdir = 'excel表名'pathname = []for (dirpath, dirnames, filenames) in os.walk(rootdir): for filename in filenames: # print(os....原创 2020-05-06 11:13:16 · 176 阅读 · 0 评论 -
urllib在python2与python3中的区别
转载自:https://blog.csdn.net/weixin_37989267/article/details/79432386Python 2 namePython 3 nameurllib.urlretrieve()urllib.request.urlretrieve()urllib.urlcleanup()urllib.request.urlcleanup()urllib.quote(...转载 2020-02-10 16:01:42 · 180 阅读 · 0 评论 -
python3安装MySQLdb
linuxapt-get install python-dev libmysqlclient-devapt-get install python3-devpip install mysqlclientwindowspip install mysqlclient-1.3.14-cp37-cp37m-win_amd64.whl验证不报错即可:import MySQLdb...原创 2020-02-10 14:19:30 · 234 阅读 · 0 评论 -
工作笔记(python给excel加密)
python给excel加密,给文件设置为只可读不可编辑,若编辑则需要密码from xlsxwriter.workbook import Workbookbook = Workbook(r"新excel文件路径")sheet = book.add_worksheet('ceshi') #添加sheet# Add separate format for unlocked cells...原创 2020-01-20 16:39:58 · 5142 阅读 · 0 评论 -
pandas与mongoDB
import pandas as pdfrom pymongo import MongoClientdef _connect_mongo(host, port, username, password, db): """ A util for making a connection to mongo """ if username and password: ...翻译 2019-11-02 11:26:27 · 471 阅读 · 0 评论 -
笔记:主要掌握根据字典内容同时替换多个字符串
import jsonimport reimport osimport pandas as pdfrom sqlalchemy import create_engine# 根据字典同时替换多个字符串class make_xlat: def __init__(self, *args, **kwargs): self.adict = dict(*args, **k...原创 2019-11-02 10:03:28 · 660 阅读 · 0 评论 -
笔记:多个dataframe追加写入excel的同一个sheet里
https://stackoverflow.com/questions/38074678/append-existing-excel-sheet-with-new-dataframe-using-python-pandas多个dataframe追加写入excel的同一个sheet里import pandas as pdfrom sqlalchemy import create_engine...原创 2019-10-25 13:13:31 · 8156 阅读 · 3 评论 -
pandas往excel表同一个sheet追加数据
https://blog.csdn.net/midion9/article/details/89000131转载 2019-10-24 15:29:25 · 8347 阅读 · 0 评论 -
pandas同时返回一个dataframe的前几行和后几行
pandas同时返回一个dataframe的前几行和后几行解决方法:import numpy as npdf.iloc[np.r_[0:n, -n:0]] # 同时返回前n行与后n行原创 2019-10-24 10:25:12 · 5103 阅读 · 0 评论 -
pandas常用语法总结
pandas读取数据库中的数据import pandas as pdfrom sqlalchemy import create_enginecon = create_engine('mysql+pymysql://user:password@host:3306/database?charset=utf8')pd.read_sql(query_sql, con)两个DataFrame纵...原创 2019-10-21 13:18:02 · 586 阅读 · 0 评论 -
常见题目
str = ‘aabbbcccc’写出代码要求结果为’a2b3c4’''.join('%s%s' % (i, str.count(i))for i in sorted(set(str)))python product函数的作用Product函数可以实现对矩阵做笛卡尔积from itertools import productA=[1,2],B=[3,4]print(list(pro...原创 2019-10-21 10:35:53 · 253 阅读 · 0 评论 -
常用自定义函数总结
获取文件路径def get_file_path(rootdir): for (dirpath, dirnames, filenames) in os.walk(rootdir): pathname = [os.path.join(dirpath, filename) for filename in filenames] return pathname日期转时间...原创 2019-10-21 10:20:08 · 425 阅读 · 0 评论 -
Pandas列中的字典/列表拆分为单独的列
[1] dfStation ID Pollutants8809 {"a": "46", "b": "3", "c": "12"}8810 {"a": "36", "b": "5", "c": "8"}8811 {"b": "2", "c": "7"}8812 {"c": "11"}8813 ...原创 2019-10-12 15:59:12 · 5842 阅读 · 0 评论 -
python 里使用方向键显示「^[[C^[[D」
linux Centos7 系统,系统本身自带有python2.7 使用方向键正常,然后自己又安装了的python3.6版本,也装了readline,readline-devel,但是使用python3时,方向键就是不能用,最后解决办法:再重新./configure make && make install 一下python3.6 因为我是先编译安装的python3后来才装的readline,没原创 2018-01-04 14:15:24 · 3353 阅读 · 0 评论 -
ANSI、GBK、GB2312、UTF-8、GB18030和 UNICODE 编码那些事儿
http://www.qianxingzhem.com/post-1499.html很久很久以前,有一群人,他们决定用8个可以开合的晶体管来组合成不同的状态,以表示世界上的万物。他们看到8个开关状态是好的,于是他们把这称为”字节”。再后来,他们又做了一些可以处理这些字节的机器,机器开动了,可以用字节来组合出很多状态,状态开始变来变去。他们看到这样是好的,于是它们就这机器称为”计算机”。转载 2018-01-26 17:39:24 · 371 阅读 · 0 评论 -
购物车程序
购物车程序基础要求: 1、启动程序后,输入用户名密码后,让用户输入工资,然后打印商品列表 2、允许用户根据商品编号购买商品 3、用户选择商品后,检测余额是否够,够就直接扣款,不够就提醒 4、可随时退出,退出时,打印已购买商品和余额 5、在用户使用过程中, 关键输出,如余额,商品已加入购物车等消息,需高亮显示扩展需求: 1、用户下一次登录后,输入用户名密码,直接回到上次的状态,原创 2018-01-29 15:09:53 · 508 阅读 · 0 评论 -
三级菜单
三级菜单 需求: 可依次选择进入各子菜单 可从任意一层往回退到上一层 可从任意一层退出程序 所需新知识点:列表、字典# coding=utf-8menu = { '北京':{ '海淀':{ '五道口':{ 'soho':{}, '网易':{},原创 2018-01-29 15:10:34 · 438 阅读 · 0 评论 -
简单的登陆认证程序
编写登陆认证程序: 基础需求: 让用户输入用户名密码 认证成功后显示欢迎信息 输错三次后退出程序升级需求: 可以支持多个用户登录 (提示,通过列表存多个账户信息) 用户3次认证失败后,退出程序,再次启动程序尝试登录时,还是锁定状态(提示:需把用户锁定的状态存到文件里) black_user是建立的空txt文件user_info = { 'mary': {'passwor原创 2018-01-29 15:10:50 · 829 阅读 · 0 评论 -
可变与不可变集合(set,frozenset)
https://www.cnblogs.com/panwenbin-logs/p/5519617.html转载 2018-02-16 23:23:53 · 11436 阅读 · 0 评论 -
python 安装第三方模块 报错
python 安装第三方模块 刚开始使用python3安装第三方模块报出系统错误 SyntaxError: Missing parentheses in call to ‘print’ 原因:用python3.x的版本运行只能在python2.x运行的脚本,在python3 里的print是要加括号的,2版本没有后来用python2安装,又报错: fatal error: Pytho...原创 2018-03-23 11:14:14 · 881 阅读 · 0 评论 -
python tab补全功能
编写文件tab.py vim tab.py#!/usr/bin/python# python tab fileimport sysimport readlineimport rlcompleterimport atexitimport os# tab completionreadline.parse_and_bind('tab: complete')# history f...原创 2018-04-09 11:47:43 · 523 阅读 · 0 评论 -
时间戳与本地时间转换关系
#时间转换关系 #时间戳(12323.0)与本地时间的转换(1970-01-01 11:25:23): #12323.0 ------> 1970-01-01 11:25:23 s=time.localtime(12323.0) print(time.strftime('%Y-%m-%d %H:%M:%S',s)) #1970-01-01 11:25:23 ---...原创 2018-04-09 17:15:18 · 1379 阅读 · 0 评论 -
mysql数据库修改密码的几种方法(用命令修改)
方法1: 用SET PASSWORD命令 首先登录MySQL。 格式:mysql> set password for 用户名@localhost = password(‘新密码’); 例子:mysql> set password for root@localhost = password(‘123’); 方法2:用mysqladmin 格式:mysqladmin -u用户...转载 2018-05-02 10:43:21 · 2251 阅读 · 0 评论 -
Python 命令行输出的颜色设置
转自:http://www.cnblogs.com/chjbbs/p/5706513.html Console上运行的python程序,有没有办法让print输出的文本可以显示不同的颜色? 这个其实跟python无关,跟具体所用console的类型有关系,不同的类型对应不同的控制码,如果是ansi终端,可以用ansi的控制码。 ————————————–以Linux的ansi终端为例——...转载 2018-04-27 14:47:29 · 1971 阅读 · 0 评论 -
pip源配置
linux系统下pip源配置,下载包时会默认从配置的源中找http://pypi.python.org 官方源 http://pypi.douban.com 豆瓣源 https://pypi.tuna.tsinghua.edu.cn 清华源 http://pypi.mirrors.ustc.edu.cn/simple/ 中国科学技术大学[global] timeout = 6000...原创 2018-07-10 00:28:10 · 260 阅读 · 0 评论 -
Python 库 大全
原文链接:https://www.zhihu.com/question/24590883/answer/92420471原文链接:Python 资源大全这又是一个 Awesome XXX 系列的资源整理,由 vinta 发起和维护。内容包括:Web框架、网络爬虫、网络内容提取、模板引擎、数据库、数据可视化、图片处理、文本处理、自然语言处理、机器学习、日志、代码分析等。伯乐在线已在 GitH...转载 2018-09-19 15:05:18 · 819 阅读 · 0 评论