
python学习
python基础学习
zhangvalue
在奋进的路上,大家都是独行者!
展开
-
Python的turtle库绘图-圣诞树
Python的turtle库绘图-圣诞树loading......(o゜▽゜)o☆[BINGO!]# *===================================*# -*- coding: utf-8 -*-# * Time : 2020-02-24 19:10# * Author : zhangsf# *==========================...原创 2020-02-24 19:27:12 · 3400 阅读 · 0 评论 -
Python的turtle库绘图-玫瑰花
Python的turtle库绘图-玫瑰花# *===================================*# -*- coding: utf-8 -*-# * Time : 2020-02-24 19:06# * Author : zhangsf# *===================================*from turtle import *...原创 2020-02-24 19:25:16 · 1272 阅读 · 0 评论 -
Python的turtle库绘图-樱花暗色效果
Python的turtle库绘图-暗色效果# *===================================*# -*- coding: utf-8 -*-# * Time : 2020-02-24 19:06# * Author : zhangsf# *===================================*from turtle import *...原创 2020-02-24 19:23:36 · 1029 阅读 · 1 评论 -
Python的turtle库绘图-樱花动态飘落
Python的turtle库绘图-动态飘落loading......# *===================================*# -*- coding: utf-8 -*-# * Time : 2020-02-24 19:01# * Author : zhangsf# *===================================*from t...原创 2020-02-24 19:22:11 · 14258 阅读 · 7 评论 -
Python的turtle库绘图-动态樱花
Python的turtle库绘图-动态樱花loading......效果图import turtle as Timport randomimport time# 画樱花的躯干(60,t)def Tree(branch, t): time.sleep(0.0005) if branch > 3: if 8 <= branch <...原创 2020-02-24 19:20:32 · 6023 阅读 · 0 评论 -
使用statsmodels导包时报ImportError: cannot import name 'factorial' from 'scipy.misc'
问题:使用的statsmodels更新到最新版本的scipy时出现错误ImportError: cannot import name 'factorial' from 'scipy.misc'ImportError: cannot import name 'factorial' from 'scipy.misc'报错的语句为:import statsmodels.api as ...原创 2020-02-11 22:35:15 · 12120 阅读 · 0 评论 -
解决安装Python包时超时失败ReadTimeoutError: HTTPSConnectionPool(host='files.pythonhosted.org', port=443)
问题:今天在遇到了安装Python中的statsmodels包的时候一直超时失败报错如下ReadTimeoutError: HTTPSConnectionPool(host='files.pythonhosted.org', port=443): Read timed out.之前的安装的方式是:pip install statsmodels解决办法:使用国内的镜像源...原创 2020-02-11 22:26:30 · 36748 阅读 · 14 评论 -
from scipy.misc import imread时提示无法导入imread
from scipy.misc import imread时提示无法导入imreadscipy.misc中已经没有imread了,用imageio来替代import imageio'''word词云内容,img图片路径, output输出路径'''Img = imageio.imread(img)...原创 2020-02-07 19:10:17 · 2356 阅读 · 0 评论 -
Python3报错:TypeError: 'dict_keys' object is not subscriptable
Python3报错:TypeError: 'dict_keys' object is not subscriptable解决办法:在报错的地方加上list就解决,原因暂时不详原创 2020-01-11 18:30:25 · 2553 阅读 · 0 评论 -
Python3报错:FutureWarning: Method .as_matrix will be removed in a future version. Use .values instead.
Python3报错:FutureWarning: Method .as_matrix will be removed in a future version. Use .values instead.orig_data = pdData.as_matrix()解决办法:根据报错提示将as_matrix()改为valuesorig_data = pdData.values...原创 2020-01-11 16:51:31 · 1892 阅读 · 0 评论 -
Python3问题:matplotlib中负号显示为方框的问题
Python3问题:matplotlib中负号显示为方框的问题解决办法:import matplotlib.pyplot as pltplt.rcParams['font.sans-serif']=['SimHei'] #用来正常显示中文标签plt.rcParams['axes.unicode_minus']=False #用来正常显示负号问题解决:...原创 2020-01-11 16:27:15 · 4036 阅读 · 1 评论 -
Python3 matplotlib 画图保存图片空白
Python3 matplotlib 画图保存图片空白原因是因为保存图片的时候将plt.savefig('./test.jpg')放到了plt.show()之后# 从低到高展示成绩分布图grade_distribution = sns.countplot(student['G3'])grade_distribution.set_title('成绩分布图', fontsize=30)...原创 2020-01-11 14:00:59 · 3081 阅读 · 0 评论 -
Python3报错:TypeError: unsupported operand type(s) for /: 'dict_values' and 'int'
Python3报错:TypeError: unsupported operand type(s) for /: 'dict_values' and 'int'报错原因: In python3,dict.valuesreturns adict_valuesobject, which is not alistortuple. 解决方法:Try coercing that...原创 2020-01-10 17:37:44 · 7083 阅读 · 0 评论 -
Python3报错:AttributeError: 'dict' object has no attribute 'has_key'
Python3报错:AttributeError: 'dict' object has no attribute 'has_key'出现这种错误是因为python版本兼容问题:has_key方法在Python2中方法,在Python3没有如:loc_dict.has_key(location)改为:if location in loc_dict...原创 2020-01-10 17:04:28 · 2582 阅读 · 0 评论 -
Python3报错AttributeError: 'dict' object has no attribute 'iteritems'
Python3报错: AttributeError: 'dict' object has no attribute 'iteritems'原因:iteritems是为python2环境中dict的函数 解决办法:在python3将iteritems改为items原创 2020-01-10 15:20:06 · 1713 阅读 · 2 评论 -
Python报错:ImportError: scipy/special/_ufuncs.cpython-37m-darwin.so, 2): Library not loaded
Python3在使用scipy的时候报错ImportError: dlopen(/python3.7/site-packages/scipy/special/ufuncs.cpython-37m-darwin.so, 2): Library not loaded: @rpath/libmkl_rt.dylib Referenced from: /Users/zhangsf/anaconda3/...原创 2020-01-07 21:51:51 · 3824 阅读 · 0 评论 -
ERROR conda.core.link:_execute(637): An error occurred while installing package 'None'.
在Pycharm中安装包的时候提示需要进行conda更新,可是在具体更新的时候出现了如下错误ERROR conda.core.link:_execute(637): An error occurred while installing package 'None'.AssertionError()Attempting to roll back.Rolling back transac...原创 2020-01-07 20:16:56 · 4189 阅读 · 0 评论 -
Python3使用BFS实现湖北省到全国省级行政区
Python3实现湖北省到全国省级行政区Python3使用BFS实现湖北省到全国省级行政区说明:全国34个省级行政区到湖北省的中间间隔不超过两个省,即使是台湾省和海南省,中间也绝对不会超过两个省,台湾-福建-江西-湖北,而海南-广东-湖南-湖北。地图:行政区的毗邻行政区结构:# 各个行政区的毗邻行政区距离结构 graph = { '台湾': ['福建'], '海南'...原创 2020-01-06 19:32:12 · 527 阅读 · 0 评论 -
Python3中print()函数输出多个变量
第一种方法: print("变量1", file_name, "变量2", new_name)print("变量1", file_name, "变量2", new_name) 第二种方法: print("变量1:%s 变量2:%s" % (file_name, new_name))print("变量1:%s 变量2:%s" % (file_name, new_nam...原创 2020-01-05 11:14:49 · 59900 阅读 · 0 评论 -
Python3批量修改文件名小工具
Python3批量修改文件名小工具Python3批量修改文件名小工具初衷:在下载文件夹中的文件名后缀命名太长,看着不舒服想着修改命名,可是文件太多,一个一个修改又太麻烦修改的部分:path为需要修改文件夹的目录比如 /Users/zhangsf/Movies/红楼梦/红楼梦001-060集需要修改的文件的后缀,切片获取文件扩展名比如 .mp3新文件名控制,自己视情况设置注意事项...原创 2020-01-05 10:27:36 · 1496 阅读 · 0 评论 -
Python3报错too many values to unpack (expected 3)
Python3处理多行数据集的时候报错too many values to unpack (expected 3)具体问题如下(seme, sid, rank,) = line.split('\t')原因:函数接收变量个数少于函数返回值个数导致的,因为返回4个value(seme, sid, rank, no_use) = line.split('\t')...原创 2020-01-02 21:38:02 · 35833 阅读 · 0 评论 -
Python3出现TypeError: 'int' object is not iterable
在Python3中进行迭代计算的时候出现了 错误TypeError: 'int' object is not iterable翻译过来就是 int对象是不可迭代的错误的代码是因为左边的data[index][2] 是一个列表类型,右边的不是列表形式试图将一个列表与一个非列表类型的值连接解决办法就是将右边的1换成列表形式 [1]data[index][2] +...原创 2020-01-01 16:50:23 · 4481 阅读 · 0 评论 -
UnicodeDecodeError: 'utf-8' codec can't decode byte 0x80 in position 0: invalid start byte
Python 打开.pkl文件的时候报错如下:UnicodeDecodeError: 'utf-8' codec can't decode byte 0x80 in position 0: invalid start byte解决方法:open文件时使用‘rb’方式import picklef = open('zBookInfo.pkl', 'rb')data = pickle...原创 2019-12-30 13:30:12 · 3663 阅读 · 0 评论 -
Python's 9 Tips
Python是一门技巧性很强的语言,在使用的时候往往会因为人为的原因而减缓运行的效率Python的9个小技巧1.列表推导式有一个list:bag = [1, 2, 3, 4, 5]现在想让所有元素翻倍,让它看起来是这个样子:[2, 4, 6, 8, 10]大多初学者,根据之前语言的经验会大概这样来做bag = [1, 2, 3, 4, 5]for i in ra...原创 2019-12-27 10:17:41 · 148 阅读 · 0 评论 -
ImportError: cannot import name 'cross_validation' from 'sklearn'
使用sklearn(scikit-learn) import cross_validation的时候报错如下:ImportError: cannot import name 'cross_validation' from 'sklearn'原来的代码为:from sklearn import cross_validation as cv原因:sklearn.cross_...原创 2019-12-14 15:37:10 · 7451 阅读 · 1 评论 -
kaggle案例-学生在考试数据集
kaggle案例-学生在考试数据集数据集包括8个变量gender 性别 race/ethnicity 种族 parental level of education 父母教育水平 lunch 午餐 test preparation course math score 数学 reading score 阅读 writting score 写作第一步:简单查看数据# *=...原创 2019-12-06 21:44:49 · 7653 阅读 · 0 评论 -
Python3-学生成绩预测基本求法
Python3-学生成绩预测基本求法提供的数据集中的数据是 学期,学号,排名每一个学号提供了两个学期的成绩最终根据第一学期的成绩比重0.35,第二学期的比重为0.65# -*- coding: utf-8 -*-def Weight_score(): file_score = open("../data/Score Predict.csv", encoding="un...原创 2019-12-06 21:27:48 · 3052 阅读 · 1 评论 -
Python3-zip()函数和sorted()函数
Python3-zip()函数和sorted()函数# zip()函数:将两个序列合并,返回zip对象,可强制转换为列表或字典# sorted()函数:对序列进行排序,返回一个排序后的新列表,原数据不改变# 合并两个列表,以列表类型输出list_str = ['a', 'b', 'c', 'd']list_num = [1, 2, 3, 4]list_new = zip(lis...原创 2019-12-06 21:22:11 · 770 阅读 · 0 评论 -
UnicodeDecodeError: 'utf-8' codec can't decode byte 0xc6 in position 2: invalid continuation byte
Python3中打开文件出现如下错误:UnicodeDecodeError: 'utf-8' codec can't decode byte 0xc6 in position 2: invalid continuation byte解决方法:unicode-escape编码集,他是将unicode内存编码值直接存储原来的代码file_score = open("../d...原创 2019-12-06 20:30:33 · 3257 阅读 · 0 评论 -
Initializing libiomp5.dylib, but found libiomp5.dylib already initialized.
Python3-报错:Initializing libiomp5.dylib, but found libiomp5.dylib already initialized.在具体的py文件添加如下,重新运行。import osos.environ["KMP_DUPLICATE_LIB_OK"]="TRUE"...原创 2019-12-06 16:01:07 · 2834 阅读 · 4 评论 -
Your CPU supports instructions that this TensorFlow binary was not compiled to use: SSE4.1 SSE4.2 AV
在Mac中使用Python3的时候跑程序安装TensorFlow(CPU版本)报错:Your CPU supports instructions that this TensorFlow binary was not compiled to use: AVX2 FMA原因:CPU支持AVX扩展,但是安装的TensorFlow版本无法编译使用解决方法:安装的是CPU版本(pip inst...原创 2019-12-06 15:59:17 · 493 阅读 · 0 评论 -
Python3-AttributeError: module 'tensorflow' has no attribute 'Variable'
在运行Python3程序的时候,程序一直在跑,突然之间报错:AttributeError: module 'tensorflow' has no attribute 'Variable'问题原因:该py文件命名为了tensorflow.py根据python的调用机制,它会优先import 项目中的tensorflow,从而没有各种方法。解决办法:将命名修改了,重新运行就ok。...原创 2019-12-05 20:09:46 · 3283 阅读 · 0 评论 -
Python3-ValueError:not enough values to unpack (expected 2, got 0)
报错:Python3-ValueError:not enough values to unpack (expected 2, got 0)具体的错误如下:Traceback (most recent call last): File "/Users/zhangsf/code/python/my-project/Subsidy.py", line 83, in <module&g...原创 2019-12-03 09:58:23 · 25298 阅读 · 0 评论 -
Mac-matplotlib图例中文乱码(已解决)
在Mac中使用Python import mayplotlib做可视化图表时出现如图例中中文乱码问题解决之后是下图这种情况:步骤一、下载字体SimHei并完成安装https://fontzone.net/download/simhei步骤二、复制字体到matplotlib字体目录下的ttf文件里找到本机的ttf文件夹为/Users/zhangsf/anacon...原创 2019-12-01 11:23:16 · 1061 阅读 · 2 评论 -
Mac中Pycharm格式化代码快捷键
Mac中Pycharm格式化代码快捷键不用全选command+option+L 格式化代码(L大写小写都可以)原创 2019-11-30 20:07:17 · 10402 阅读 · 0 评论 -
Mac的pycharm中快捷键command+a不能全选
问题:今天在pycharm中想使用快捷键全选结果:command+a的时候不是全选而是 show usages原因:是因为安装了ideavim插件解决方法:卸载掉ideavim插件找到这个插件ideavim卸载uninstall卸载之后提示重启,重启就ok了。...原创 2019-11-30 20:05:18 · 2481 阅读 · 0 评论 -
Python中[ : n]、[m : ]、[-1]、[:-1]、[::-1]、[2::-1]和[1:]的含义
Python中[ : n]、[m : ]、[-1]、[:-1]、[::-1]、[2::-1]和[1:]的含义[m : ]代表列表中的第m+1项到最后一项[ : n]代表列表中的第一项到第n项[-1] 代表去到最后一项[:-1]代表除了最后一个都获取到[::-1]代表逆序取,从后向前取[2::-1]代表从下标从0到2的三个数,逆序取[1:]代表从下标为1开始取到最后...原创 2019-11-30 19:27:34 · 7649 阅读 · 0 评论 -
Pandas中head( )函数
Pandas读取数据之后使用pandas的head()函数的时候,来观察一下读取的数据head( )函数只能读取前五行数据如下图所示在查看这个head()函数的具体实现如下: def head(self, n=5): """ Return the first `n` rows. This function returns the ...原创 2019-11-30 18:59:48 · 58158 阅读 · 2 评论 -
Python3-发送Outlook邮件带附件
使用的环境是在Python3.6、系统Windows10先Windows安装pypiwin32:详情见https://zhangvalue.blog.youkuaiyun.com/article/details/103308248安装好了pypiwin32之后具体代码如下# *===================================*# -*- coding: utf-8 ...原创 2019-11-29 13:07:04 · 2365 阅读 · 0 评论 -
Python3-AttributeError: module 'sys' has no attribute 'setdefaultencoding
Python3字符串默认编码unicode, 所以sys.setdefaultencoding不存在去掉sys.setdefaultencoding('utf8')原创 2019-11-29 12:56:47 · 1624 阅读 · 0 评论