![](https://img-blog.csdnimg.cn/20201014180756928.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
python
文章平均质量分 54
买猫咪的小鱼干
这个作者很懒,什么都没留下…
展开
-
Debug | Pycharm | autopep8: error: cannot mix stdin and regular files
Debug | Pycharm | autopep8: error: cannot mix stdin and regular files报错信息:使用Pycharm运行autop8的时候遇到了如下问题:autopep8 --in-place --aggressive --aggressive C:\Users\***\OneDrive - ***\JupyterNotebook\***\mamcala.pyautopep8: error: cannot mix stdin and regular原创 2021-10-11 12:31:08 · 737 阅读 · 1 评论 -
Python | 返回函数 | partial&局部函数闭包
Python | 返回函数 | yield & partial用法题目测试答案partial()局部函数讲解partial()局部函数其他在帮朋友解决一个问题的时候遇到了这个,恍惚间才发现自己不熟悉,mark下题目测试测试代码assert favorite_subject(0)=="statistics"assert favorite_subject(1)()=="statistics"assert favorite_subject(5)()()()()()=="statistics原创 2021-05-02 10:22:15 · 181 阅读 · 0 评论 -
Anaconda | conda基本操作
自建自用Anaconda | conda基本操作环境查看环境创建环境激活环境关闭环境删除环境克隆环境重命名环境安装包查看安装包删除某个包其他更新conda添加镜像源恢复默认环境查看环境conda env list /conda info -e创建环境conda create -n your_env_name python=x.x激活环境conda activate your_env_name关闭环境deactivate env_name/activate root删除环原创 2021-05-02 09:46:47 · 235 阅读 · 0 评论 -
Python | 模块/包/库/git安装
Python | 模块/包/库/git安装引言pip+gitpip+.whlsetup.py参考资料引言主要介绍下python、pip、git等安装模块、包、库、github等的操作pip+gitpip install git+xxx.git //xxx其中xxx:包所在的github仓库位置比如: pip install git+https://github.com/nicolargo/glances.gitpip+.whl首先进入xxx.whl文件所在位置,然后直接:pip insta原创 2021-05-01 22:52:48 · 1333 阅读 · 0 评论 -
Debug | Object of type ‘int32/int64/ndarray‘ is not JSON serializable
报错信息:在写入json文件的时候出现了如下问题:Object of type ‘int32/int64/ndarray’ is not JSON serializable问题分析:json的解码类型不包括numpy.array,因此无法写入参考官方文档,json和python对应如下:JSONPythonobjectdictarrayliststringstrnumber (int)intnumber (real)floattru原创 2021-05-01 22:42:55 · 125 阅读 · 0 评论 -
Python | list交集、并集、差(补集)、对称差集
Python | list交集、并集、差(补集)、对称差集总结交集并集差集对称差集主要参考博客,其中方法分为集合运算符和集合方法两种,推荐第二种,效率更高,当然偷懒,数据小不追求效率可以用运算符。总结集合运算符方法交集&.intersection()并集|.union()差集-.difference()对称差集^.symmetric_difference()交集a = [0,1,2,3,4]b = [0,2,4,6,8]lis原创 2021-05-01 20:59:02 · 1143 阅读 · 0 评论 -
Python | numpy输出排名
Python | numpy输出排名引言排序 np.sort()排序序号 np.argsort()排名引言我们知道np.sort()可以对向量进行排序,而排名怎么做呢,mark下。先简单介绍下np.sort()和np.argsort()这两个函数排序 np.sort()排序,默认升序import numpy as nptemp = np.array([0,1,2,3,4,5,4])tsort = np.sort(temp)tsortarray([0, 1, 2, 3, 4, 4,原创 2021-05-01 19:34:49 · 2293 阅读 · 3 评论 -
Debug | Variable ... already exists, disallowed. Did you mean to set reuse=True ...
报错信息:colab运行的时候遇到了如下问题:ValueError: Variable eval_net/l1/w1 already exists, disallowed. Did you mean to set reuse=True or reuse=tf.AUTO_REUSE in VarScope? Originally defined at: …问题分析:参考这篇,控制台已保存上次运行结束的变量。所以会报变量已存在的问题解决方案:参考这篇博客solution 1:重开,resta原创 2021-04-10 11:02:52 · 1171 阅读 · 0 评论 -
Python | 查看安装包的版本
Python | 查看安装包的版本pip listpythonpip listcmd中运行pip list,直接展示所有:python比如在jupyter notebook中,一般在import之后通过version或者__version__获得相应模块版本,比如:import syssys.version3.7.10 (default, Feb 20 2021, 21:17:23) [GCC 7.5.0]一般version比较少,多是__version__import pandas原创 2021-04-10 10:39:29 · 1371 阅读 · 0 评论 -
Python | 保留*位小数
Python | 保留*位小数四舍五入printroundnumpy.around多个数字无四舍五入(字符串)切片re以两位小数为例四舍五入printn=1.2345print("%.2f" % n)1.23roundn=1.2345dn=2round(n,dn)1.23numpy.aroundimport numpy as npn=1.2345dn=2np.around(n,dn)1.23多个数字import numpy as npns = [1.234原创 2021-04-10 10:06:49 · 98 阅读 · 0 评论 -
Python | pkg_resources简介
Python | pkg_resources简介介绍安装用法所需依赖包安装缺失包参考网站介绍参见pkg_resources官方文档,pkg_resources模块提供了运行时工具,用于查找,自省,激活和使用已安装的Python发行版。(直接翻译,不知道咋适合)安装pip install pkg_resources即可用法所需依赖包import pkg_resourcespkg_resources.require('pandas')[pandas 1.1.3 (g:\programfil原创 2021-04-10 09:29:13 · 18806 阅读 · 0 评论 -
Debug | AttributeError: ‘numpy.int64‘ object has no attribute ‘to_pydatetime‘
缘由在使用pyfolio遇到了如下报错:/usr/local/lib/python3.7/dist-packages/pyfolio/timeseries.py in gen_drawdown_table(returns, top)1006 recovery,1007原创 2021-04-09 18:04:44 · 5145 阅读 · 3 评论 -
Debug | InvalidArchiveError(‘Error with archive ...\\anaconda3\\pkgs\\yfinance-0.1.54-py_0.tar.bz2.
安装yfinance踩坑安装报错报错信息问题分析解决尝试S1:删除重来 (failed)S2:人工解压 (succeed:)S3:换pip安装 (w4trying)安装根据官网pip安装:pip install yfinance --upgrade --no-cache-dirconda安装:conda install -c ranaroussi yfinance 直接conda install yfinance 会找不到报错报错信息在安装yfinance运行conda install -c原创 2021-04-07 12:30:46 · 2051 阅读 · 3 评论 -
Python | HEX16进制与RGB10进制颜色互转
背景知识hex:hex → rgb原创 2021-04-01 21:35:22 · 3266 阅读 · 0 评论 -
Python | os文件函数
Python | os文件函数函数介绍转到文件目录:os.chdir()列出所有文件:os.listdir()文件是否存在:os.path.exists()重命文件目录:os.rename()组合拳实例:重命名文件函数介绍转到文件目录:os.chdir()os.chdir(path)列出所有文件:os.listdir()os.listdir(path)其中,如果path不输默认为输出当前目录所有文件~比如:import osPACKAGE_PATH =r'/content/drive/My原创 2021-03-30 21:40:39 · 165 阅读 · 1 评论 -
Debug | UnicodeDecodeError: ‘gbk‘ codec can‘t decode byte 0xbf in position 2: illegal multibyte sequ
报错信息:UnicodeDecodeError: 'gbk' codec can't decode byte 0xbf in position 2: illegal multibyte sequence问题分析:with open(path+'/'+file) as f:是在处理md文本文件时候遇到的。大致意思是当内部编码转化成 gbk编码时出错,认为我们的文件并不是gbk编码,可能是utf-8编码。解决方案:open函数默认 gbk编码,这里指定编码方式即可,比如这里指定utf-8解决问题原创 2021-03-28 17:03:27 · 458 阅读 · 0 评论 -
Debug | ERROR: Command errored out with exit status 1
报错信息:在安装pip install gym的时候遇到了这个问题:ERROR: Command errored out with exit status 1: 'd:\python391\python.exe' -u -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'C:\\Users\\84468\\AppData\\Local\\Temp\\pip-install-anu13qxv\\pillow_61f83bcd922f4175ac原创 2021-03-27 22:22:07 · 859 阅读 · 0 评论 -
python | 2、10、16进制转换
python | 2、8、16进制转换原创 2021-03-27 22:04:40 · 286 阅读 · 0 评论 -
python | 字典合并
python | 字典合并合并(更新)字典字典value相加合并(不代替)字典相同键整合成列表合并(更新)字典key如果相同,则会被覆盖A = {'a': 11, 'b': 22}B = {'b': 48, 'd': 13}#update() 把字典B的键/值对更新到A里A.update(B)print(A){'a': 11, 'b': 48, 'd': 13}或者pythonic的字典拆分:A = {'a': 11, 'b': 22}B = {'b': 48, 'd': 13}原创 2021-03-27 21:42:01 · 175 阅读 · 0 评论 -
python | 字符串去除(中文、英文、数字、标点符号)
python | 字符串去除(中文、英文、数字、标点符号)去除标点符号英文字符:string.punctuation中文字符:zhon.hanzi.punctuation去除英文s1: re.subhttps://blog.csdn.net/weixin_38819889/article/details/105389248https://blog.csdn.net/qq_36098284/article/details/89061572去除标点符号英文字符:string.punctuationpu原创 2021-03-27 20:29:11 · 46273 阅读 · 5 评论 -
python | 字典遍历
python | 字典遍历遍历key遍历value遍历key和value定义方法读取key和value直接上例子:stus = { # key: value 'a':1, 'b':2, 'c':3}遍历keyfor key in stus: print (key)abcfor key in stus.keys(): print (key)abc遍历valuefor value in stus.values(): p原创 2021-03-27 18:36:09 · 68 阅读 · 0 评论 -
python | lambda
Here’s an example of lambda that takes in three parameters and adds the first two.my_function = lambda a, b, c : a + bmy_function(1, 2, 3)3原创 2021-03-27 16:47:58 · 69 阅读 · 0 评论 -
python | map
Here’s an example of mapping the min function between two lists.store1 = [10.00, 11.00, 12.34, 2.34]store2 = [9.00, 11.10, 12.34, 2.01]cheapest = map(min, store1, store2)cheapest<map at 0x2177d83a1c0>Now let's iterate through the map object原创 2021-03-27 16:18:50 · 92 阅读 · 0 评论 -
python | 计时timeit | list & dict函数运行时间
python | 计时timeit | list & dict函数运行时间timeitListe.g. list添加元素e.g. list popList operators' big-O efficiencyDictionariesDictionary operators' big-O efficiencye.g. Comparison: in (list & dict)timeit导入:import timeitfrom timeit import Timer首先用timei原创 2021-03-13 12:20:32 · 343 阅读 · 1 评论 -
python | Class类(以Fraction为例)
python | Class类(以Fraction为例)Class__init__()printshow()__str__()__eq____add__测试用例总代码Classinit()class Fraction: def __init__(self,top,bottom): self.num = top self.den = bottomprintshow()def show(self): print(self.num, "/", self.de原创 2021-03-11 10:54:05 · 518 阅读 · 0 评论 -
python | 报错函数 | try except | raise
python | 报错函数 | try except | raisepython 报错函数try exceptraisepython 报错函数在自己写代码的时候,有时候会遇到error的情况,比如:>>> a_number = int(input("Please enter an integer "))Please enter an integer -23>>> print(math.sqrt(a_number))Traceback (most recent原创 2021-03-10 11:29:17 · 1969 阅读 · 0 评论 -
python | 输入输出input print
复习,mark一下~python | 输入输出input print输入 input输出 print输入 inputinput赛高,直接放代码输入的结果都是str类型,如果希望输入数字,需要类型转换user_name = input("Please enter your name ")print("Your name in all capitals is",user_name.upper(),"and has length", len(user_name))user_radius = in原创 2021-03-10 11:09:41 · 232 阅读 · 0 评论 -
python | 基本数据类型函数
python | 基本数据类型函数SequenceOperations on Any SequenceListMethods Provided by ListsStringMethods Provided by StringsSetOperations on a SetMethods Provided by SetsDictOperators Provided by DictionariesMethods Provided by Dictionariesmark一下SequenceOperations原创 2021-03-07 21:06:46 · 115 阅读 · 0 评论 -
python | if else一行简写
https://blog.csdn.net/zm429438709/article/details/80213414#第一种 “值1 if 条件 else 值2”,把它看成天平的话就非常好记忆了a, b, c =1, 2, 3c = a if a>b else bc2原创 2021-03-07 11:03:58 · 1594 阅读 · 0 评论 -
Debug | ERROR: Could not install packages due to an OSError: [WinError 5] 拒绝访问。
在安装pip install jupyterthemes时遇到了无法快乐pip的情况:报错信息ERROR: Could not install packages due to an OSError: [WinError 5] 拒绝访问。: 'C:\\Users\\...\\AppData\\Local\\Temp\\pip-uninstall-xq6nqdvs\\jupyter-notebook.exe' Consider using the --user option or check the per原创 2021-03-03 12:27:42 · 62471 阅读 · 19 评论 -
Python | Dates and Times (datetime)
Python | Dates and Times(datetime)Dates and Times导入tm.time()dt.timedelta()dt.date.today()Dates and Times介绍下python下datetime和time的基本用法导入import datetime as dtimport time as tm`time` returns the current time in seconds since the Epoch. (January 1st, 19原创 2021-02-25 12:45:28 · 147 阅读 · 0 评论 -
Python | 排列组合数【AC】计算
缘由:计算排列组合数,比如CnmC_n^mCnm、AnmA_n^mAnm等时,一筹莫展方法:scipy包中有comb和perm函数:安装scipypip install scipy即可comb perm导入:from scipy.special import comb, perm排列数AnmA_n^mAnmperm:>>> perm(3,2)6.0组合数CnmC_n^mCnmcomb:>>> comb(3,2)3.0...原创 2021-02-21 17:24:19 · 1811 阅读 · 0 评论 -
Python | 输出分数形式(Fraction)
缘由:用python做除法运算默认只能得到小数形式,有时候想输出成分数形式。方法:用Fraction函数即可:Fraction | 输出分数形式Fraction入门教程FractionFraction函数是python中实现分数的一个模块,通过pip install Fraction安装相应包。入门教程分数作为Fraction类存在:>>> from fractions import Fraction>>> f = Fraction(2,3)>原创 2021-02-21 16:54:54 · 6418 阅读 · 0 评论 -
python | tqdm介绍与入门
python | tqdm介绍与入门tqdm安装入门教程Iterable-basedtqdm这里介绍下一个酷炫的python神器当你在跑循环却不知道跑到哪了,用print(i)又觉得索然无味的时候,tqdm可以很好解决问题。e.g.安装Github tqdm看详细介绍或者pip install tqdm入门教程官网说明tqdm主要有3个用法,Iterable-based, Manual 和 Module,这里简单介绍下Iterable-based的,其他可以查看官网Iterable-ba原创 2021-02-09 14:29:03 · 432 阅读 · 1 评论 -
Python | 判断变量类型 | isinstance() & type()用法介绍
Python | 判断变量类型isinstance() & type()注意isinstance() & type()直接上代码l = list('123')print(l)type(l)type(l).__name__type(l).__name__=='list'isinstance(l,list)isinstance('a',list)# 是元组中的一个返回 Trueisinstance (l,(str,int,list)) ['1', '2', '3'原创 2021-02-08 13:37:21 · 441 阅读 · 0 评论 -
Coursera | Using Python to Access Web Data(University of Michigan)| Quiz
Using Python to Access Web Data是超级经典的密歇根python课程Python for Everybody Specialization的第三门。缘由是之前学的爬虫有点忘了,打算复习下。这门课怎么说,从基础原理方面出发,算是弥补了我之前无系统学习的知识漏洞,也很有趣。但是,也要提几点:计网知识真的忘的差不多了,感觉理论还是有点吃力,如果要更深入理解,可能要和这个联动课程Internet相关的一起互相补充;最后上完实践机会没达到预期,可能是从基础一步步来,个人是希望更多点实原创 2021-02-03 22:38:14 · 1388 阅读 · 0 评论 -
Python | pip设置代理 & 更换镜像
pip | 设置代理 & 更换镜像问题缘由设置代理(cmd, bash, powershell)更换镜像问题缘由之前pip install ...使用国内镜像源提高下载速度,后来学会科学上网后,就不用国内源,一路风雨无阻,今天再运行时,出现如下报错:WARNING: Retrying (Retry(total=4, connect=None, read=None, redirect=None, status=None)) after connection broken by ‘ProxyEr原创 2021-02-01 21:41:56 · 25953 阅读 · 2 评论 -
SQL | SQL+Python API相关入门教程(DB&SQL4DS笔记)
SQL+Python API相关入门教程学了Coursera上的Databases and SQL for Data Science,里面介绍了SQL基本用法以及相关Python API的用法,这里做个笔记,归纳下SQL常用的syntax,放丢失~原创 2021-01-27 16:33:27 · 784 阅读 · 0 评论 -
Debug | module ‘folium.features‘ has no attribute ‘CircleMarker‘
报错信息AttributeError: module 'folium.features' has no attribute 'CircleMarker'分析folium.features.CircleMarker()出问题,应该是folium改版把CircleMarker从folium.features去掉了解决方法将folium.features.CircleMarker()改成folium.CircleMarker()即可...原创 2020-12-29 14:26:12 · 388 阅读 · 0 评论 -
Debug | <urlopen error [WinError 10061] 由于目标计算机积极拒绝,无法连接。>
报错信息URLError: <urlopen error [WinError 10061] 由于目标计算机积极拒绝,无法连接。>分析发现是sns.load_dataset这里出了问题。在下载网络数据等文件的时候,常出现该问题。解决方法solution 1: 在浏览器代理设置中,将局域网设置中将代理服务器取消选中solution 2: 在浏览器代理设置中将自动检测打开,设置–>代理设置–>弹出Internet属性–>局域网设置–>自动检测设置–>重新运行原创 2020-12-28 16:33:51 · 7678 阅读 · 0 评论