
Python
真理的追求者
这个作者很懒,什么都没留下…
展开
-
入门级Python代码实时获取股市数据
入门级Python代码实时获取股市数据原创 2022-05-20 22:52:42 · 1232 阅读 · 0 评论 -
pandas merge 使用方法
import pandas as pdleft = pd.DataFrame({'key1': ['K0', 'K0', 'K1', 'K2'], 'key2': ['K0', 'K1', 'K0', 'K1'], 'A': ['A0', 'A1', 'A2', 'A3'], 'B': ['B0', 'B1', 'B2', 'B3']})right = pd.DataFra.原创 2020-05-24 21:51:33 · 601 阅读 · 0 评论 -
单例模式实现日志文件的分文件存储。
利用单例模式实现日志文件分文件存储。#!/usr/bin/env python# -*- coding: utf-8 -*-# @Time : 2020/5/11 23:21# @Author : Zheng guoliang# @Version : 1.0# @File : log_util.py# @Software: PyCharm"""1.需求功能: 利用单例模式将日志分文件存储2.实现过程:"""import osimport sysimp.原创 2020-05-12 08:22:27 · 362 阅读 · 0 评论 -
pandas 应用记录
插入值pandas_df.index = range(1, len(pandas_df) + 1) # set index from 1pandas_index = pandas_df.index # 将dataframe的索引赋给一个变量pandas_df.insert(0, 'index', pandas_index) # 第一个参数是列插入的位置...原创 2020-04-16 08:15:33 · 238 阅读 · 0 评论 -
python 静态检查
1.pipinstall安装flake8,pylint,autopep8这三个第三方库。2.设置相应的插件信息。具体填写信息如下:flake8$PyInterpreterDirectory$/python-m flake8 --show-source --statistics --exclude venv,migrations $FilePath$$ProjectF...原创 2020-01-30 10:14:18 · 431 阅读 · 0 评论 -
python3 pandas merge使用
# 更改列名df_obj1 = df_obj1.rename(columns={'key':'key1'})df_obj2 = df_obj2.rename(columns={'key':'key2'})原创 2019-12-22 22:36:18 · 304 阅读 · 0 评论 -
python3 时间性能和空间性能分析
import sysfrom line_profiler import LineProfilerfrom memory_profiler import profile# @profile(precision=4,stream=open('memory_profiler.log','w+'))# @profiledef my_function(): print("hell...原创 2019-12-12 23:15:05 · 527 阅读 · 0 评论 -
python3.7 解决安装第三方库失败问题
摘要:解决Microsoft visual c++ 14.0 is required问题。在安装line_profiler时遇到这个问题的,安装其他组件如果遇到类似问题,解决方法大致相同。https://www.lfd.uci.edu/~gohlke/pythonlibs/#line_profiler...原创 2019-12-12 22:26:10 · 1590 阅读 · 0 评论 -
python3 对''的数据进行指定格式填充
def fillNaG(x): for i,v in x.items(): if v=='': x[i]='-' return xdef test12(): INPUTFILE1 = os.path.join(BASE_PATH, 'Students6.xlsx') datas = ExcelUntil.readExcel...原创 2019-11-12 23:52:19 · 470 阅读 · 0 评论 -
pyhton3 pandas dataframe数据的增删改查
def test10(): INPUTFILE1 = os.path.join(BASE_PATH, 'Students6.xlsx') datas = ExcelUntil.readExcelFile(INPUTFILE1, headerRow=0) page_01=datas['Page_001'] page_02=datas['Page_002'] ...原创 2019-11-03 18:46:31 · 419 阅读 · 0 评论 -
python3 pandas 数据求和,求平均处理
def test09(): INPUTFILE1 = os.path.join(BASE_PATH, 'Students_Duplicates.xlsx') datas = ExcelUntil.readExcelFile(INPUTFILE1, headerRow=0, indexCol='ID') newdatas={} for sheetname,sheet...原创 2019-11-03 16:59:59 · 2065 阅读 · 0 评论 -
python3 pandas matplotlib绘图
def test03(): INPUTFILE1 = os.path.join(BASE_PATH, 'Students1.xlsx') datas = ExcelUntil.readExcelFile(INPUTFILE1, headerRow=0) for sheetname,sheetdatas in datas.items(): print(she...原创 2019-11-03 13:27:25 · 502 阅读 · 0 评论 -
Python3 pandas 数据过滤和排序操作
筛选def validate_age(age): return 18 <= age <= 29def validate_score(score,arg): return arg <= score for sheetname, sheetdatas in studentdatas.items(): print(sheet...原创 2019-11-03 10:42:46 · 1009 阅读 · 0 评论 -
python3 pandas 过滤,删除,重新设定索引
def fileterdata(targetname): newdatas={} for keyname,valuedatas in datas.items(): temp=valuedatas[valuedatas['Name']==targetname].reset_index(drop=True) newdatas[keyname]=temp...原创 2019-10-29 23:58:03 · 2010 阅读 · 1 评论 -
Python3 pandas 自定义输出excel样式
import pandas as pdimport randomimport numpy as npimport os## data = [10, 20, 30, 40, 50, 60]# df = pd.DataFrame({'Heading': data,# 'Longer heading that should be wrapped...原创 2019-10-27 21:48:54 · 20263 阅读 · 0 评论 -
pandas 去重操作
原创 2019-10-26 07:41:07 · 3461 阅读 · 0 评论 -
Python pandas 处理数据的一些技巧与实现
def test08(): INPUTFILE1 = os.path.join(BASE_PATH, 'Student_Score.xlsx') datas = ExcelUntil.readExcelFile(INPUTFILE1, headerRow=0, indexCol='ID') if 'Students' ...原创 2019-10-26 00:03:17 · 264 阅读 · 0 评论 -
pandas 排序
self._datasortedData1=values.sort_values(by=['Name2','Price1','Name'],ascending=(False,True,True)) # 逆序,顺序,顺序原创 2019-10-25 23:06:22 · 384 阅读 · 0 评论 -
Python3 pandas dataframe 数据拼接
a = pd.DataFrame() a['A'] = [1, 2, 3, 4, 5] a['B'] = [6, 7, 8, 9, 0] b = a c = pd.concat((c, b), axis=1) # 拼接到列后,列增多 print(c) print("*"*30) c = pd.concat((a, b), axis...原创 2019-10-25 06:44:04 · 682 阅读 · 0 评论 -
python3 自定义比较器
摘要:在一些场景中,需要重新对已有的数据排序,可能所给出的数据类型或者数据数量较多,需要给定排序规则。import functoolsdef by_score(t1,t2): if t1[0]>t2[0]: return 1 elif t1[0]<t2[0]: return -1 else: if t1[...原创 2019-10-24 07:12:51 · 837 阅读 · 0 评论 -
windows 修改jupyter notebook 默认路径设置
摘要:为了打开jupyter能够打开后,直接打开至指定的目录。原创 2019-08-24 10:53:55 · 481 阅读 · 0 评论 -
python 环境安装
摘要:主要目的在于熟悉python 编译环境的安装 。在开发过程中会遇到各种奇葩问题,但是这些问题的根源在于基本上都是软件环境未设置好。同时对软件编译环境的不熟悉。为了减少这些不必要的麻烦。将python安装过程进行记录。1.软件下载地址:1.1 方式1:https://mirrors.tuna.tsinghua.edu.cn/anaconda/archive/1.2 方式2:http...原创 2019-08-23 23:24:40 · 230 阅读 · 0 评论 -
Python json序列化 反序列化
import json# 序列化 反序列化print(dir(json))d1=dict(name='小米',age=2,score=99)print(d1)strs=json.dumps(d1)print(strs)d2=json.loads(strs)print(d2)原创 2018-10-18 21:35:09 · 554 阅读 · 0 评论 -
python pandas读取excel中多个不同sheet表格存在的问题
摘要:不同方法读取excel中的多个不同sheet表格性能比较# 方法1def read_excel(path): df=pd.read_excel(path,None) print(df.keys()) # for k,v in df.items(): # print(k) # print(v) # print(t...原创 2019-08-11 22:29:05 · 15801 阅读 · 1 评论 -
JAVA 调用Python的两种实现方式
摘要:jpython是python编程语言的100%存JAVA实现。将Python源代码编译成JAVA字节码,并在任何JAVA虚拟机上运行产生的字节码。Jpython是与JAVA的最大无缝平滑集成连接。 Cpython 是python的参考实现,C编写,把Python编译成中间态的字节码,然后有虚拟机解释 Anaconda里面用到了CPy...原创 2019-08-24 18:30:14 · 913 阅读 · 0 评论 -
python 正则匹配的简单使用
摘要:熟悉python中的正则匹配规则;\w\W \d\D \s\S ; *?+; ^|; () \\ 的用法import redef demo_re(): str='zhengguoliang2019wuhan0812csu2012' p1=re.compile('[\d]+') p2=re.compile('\d+') # 一个或者一个以上 p...原创 2019-08-12 23:25:38 · 358 阅读 · 0 评论 -
关于jupyter notebook密码设置
对于一个jupyter编辑器使用的新手,更换浏览器或者Logout后,需要输入密码进行登陆时1.windows下,打开命令行,重新生成一个jupyter配置文件: 1 jupyter notebook--generate-config 2.修个配置文件,找到这个新生成的文件:Windows:C:\Users\USERNA...原创 2019-07-27 16:31:41 · 1512 阅读 · 0 评论 -
python 函数式编程
摘要:函数式编程lambda,map,reduce,filter的应用。其具有三大特性:不可变数据,函数可以像变量一样使用,尾递归优化,每次递归都重用stack。优点在于:并行,惰性求值,确定性。from functools import reduceimport random# 函数式编程def inc(x): def incx(y): return x...原创 2019-08-14 21:35:54 · 194 阅读 · 0 评论 -
python 迭代器和生成器的区别
目的:区分迭代器和生成器。生成器属于一种惰性计算;属于生成器的不一定是迭代器,属于迭代器的一定是生产器;迭代器可以next()函数进行访问,生产器通过for进行访问遍历。# 一维情况下做赋值操作# 生成器 从开头 ,Next,用于惰性计算# 无任何生成初始化的开销,省内存, 用到了才计算,未用到,不计算# yield 可控多线程import timedef func_test...原创 2019-08-10 17:57:12 · 741 阅读 · 0 评论 -
字符串翻转,素数问题 Python解决
# 字符串翻转strr=" i love china! "print(strr)str1=list(strr)def reverse(str,L,R): while L<R: t=str[L] str[L]=str[R] str[R]=t L+=1 R-=1 return str ...原创 2018-10-17 15:46:54 · 435 阅读 · 0 评论 -
四舍五入 floor,ceil,round
print(math.floor(2.34)) #2print(math.ceil(2.34)) #3print(round(2.34)) #2print(round(2.54)) #3原创 2018-10-17 15:26:01 · 161 阅读 · 0 评论 -
Python 装饰器函数 wraps 利用缓存查询原理,加速递归
# 装饰器函数def foo(fn): def wrappers(): print("hello, %s" %fn.__name__) fn() print("bye, %s" %fn.__name__) return wrappers @foodef fooo(): print("i am fooo")...原创 2018-10-19 09:49:49 · 452 阅读 · 0 评论 -
Python json序列化 反序列化,map,reduce,filter
import json# 序列化 反序列化print(dir(json))d1=dict(name='小米',age=2,score=99)print(d1)strs=json.dumps(d1)print(strs)d2=json.loads(strs)print(d2)print("-----------------------------------------")...原创 2018-10-19 09:24:46 · 1601 阅读 · 0 评论 -
Python 文件读取与存储
file1=open('pima-indians-diabetes.txt','r')file2=open('out.txt','w+')#data=file1.read()i=0while True: line=file1.readline() tt='"'+line[:-1:1]+'"'+',' if i<3: print(tt) ...原创 2018-10-18 21:38:31 · 1256 阅读 · 0 评论 -
Python 面向对象
# -*- coding: utf-8 -*-"""Created on Thu Oct 18 11:26:31 2018@author: admin"""#面向对象class Student: __school='csu' def __init__(self,name,age,score=100): self.name=name ...原创 2018-10-18 20:23:58 · 153 阅读 · 0 评论 -
python list,tuple,set,dict相关操作
# -*- coding: utf-8 -*-"""Created on Thu Oct 18 10:30:51 2018@author: admin"""#list操作d=[i for i in range(10)]print(d)#添加元素d.append('x')t=[493,'zgl','csu',98]d.extend(t)print(d)d.inser...原创 2018-10-18 11:26:14 · 356 阅读 · 0 评论 -
python的一些总结点
python是什么? Python是一种解释型语言。这就是说,与C语言和C的衍生语言不同,Python代码在运行之前不需要编译。其他解释型语言还包括PHP和Ruby。 Python是动态类型语言,指的是你在声明变量时,不需要说明变量的类型。你可以直接编写类似x=111和x="I'm a string"这样的代码,程序不会报错。 Python非常适合面向对象的编程(OOP),...转载 2018-10-04 23:02:41 · 546 阅读 · 0 评论 -
Python调用C++ 测试
Python调用C++(类)动态链接库 需要extern "C"来辅助,也就是说还是只能调用C函数,不能直接调用方法,但是能解析C++方法。不是用extern "C",构建后的动态链接库没有这些函数的符号表。 #include <iostream>using namespace std;class TestLib{ public: ...原创 2018-08-01 20:20:24 · 643 阅读 · 0 评论 -
sklearn.Cross-validation
https://blog.youkuaiyun.com/mr_tyting/article/details/73440712原创 2018-07-05 08:21:12 · 158 阅读 · 0 评论 -
Python 第一次作业
B=b'China\nhello\tworld!\n'print(B)s=B.decode()print(s)print(s.encode())print(s)b'China\nhello\tworld!\n'Chinahello world!b'China\nhello\tworld!\n'Chinahello world!A=' hello world ';print...原创 2018-05-24 19:59:41 · 335 阅读 · 0 评论