python
木头生辉
这个作者很懒,什么都没留下…
展开
-
python数据抓取中空格的影响
抓取一个网站,在定位后,只抓取前五行。无意中多了一个空格,数据一直不能正常显示。在python数据抓取中,多一个空格或少一个空格,中间的差异的很大的。原创 2023-04-18 23:07:33 · 373 阅读 · 1 评论 -
PyQuery无法定位的解决
常用的定位方式是:选中——右键“copy”——“copyselector”之后先进行了页面的初始化,初始化正常,但是想要通过以上方式提取列表数据时提取值为空。经过测试,手动查找路径后,可以正常提取列表值。一、PyQuery定位问题。原创 2022-09-02 07:31:45 · 317 阅读 · 0 评论 -
python+selenium提取数据
python+selenium直接调出标签中数据原创 2022-07-12 23:01:41 · 3216 阅读 · 0 评论 -
ModuleNotFoundError: No module named ‘sqlalchemy‘
报错ModuleNotFoundError: No module named 'sqlalchemy'解决办法:pip install flask-SQLAlchemy安装后原创 2021-12-20 21:54:20 · 10595 阅读 · 0 评论 -
chromedriver版本更新
chrome版本更新后,chromedriver没有及时更新,报错查看浏览器版本到渠道官网下载文件http://chromedriver.storage.googleapis.com/index.html找到python安装路径,直接替换可以正常运行。。原创 2021-12-02 21:48:47 · 629 阅读 · 0 评论 -
chromedriver版本下载地址
下载地址:chromedriver.storage.googleapis.com/index.html原创 2021-10-13 22:29:31 · 173 阅读 · 0 评论 -
python创建DataFrame,并实现DataFrame的转置
import pandas as pdlist={'aa':'123','bb':'456','cc':'张三'}print(list)a=list.keys()b=list.values()df=pd.DataFrame([a,b],index=['citye','code']) #创建dataframeprint(df)df2=pd.DataFrame(df.values.T,index=df.columns,columns=df.index) #转置print(df2).原创 2021-07-07 17:06:06 · 3621 阅读 · 0 评论 -
python中保存csv文件时中文出现乱码
保存CSV文件出现乱码程序中运行正常解决办法:在utf-8后面加sig再次运行后,中文可以正常保存原创 2021-07-07 07:41:02 · 932 阅读 · 0 评论 -
pyquery中通过id的部分字段定位
全部定位的,可以直接使用items = doc('[id*=line127701]:lt(6)').items()# items = doc('[id^=line127701]')原创 2021-06-03 09:24:24 · 408 阅读 · 0 评论 -
selenium中通过ID的部分来定位节点
正常情况下的定位:sixth_item = driver.find_element_by_id("coption5")转载 2021-06-02 18:38:35 · 363 阅读 · 0 评论 -
selenium规避检测
现在不少大网站有对selenium采取了监测机制。比如正常情况下我们用浏览器访问淘宝等网站的 window.navigator.webdriver的值为undefined。而使用selenium访问则该值为true。那么如何解决这个问题呢?只需要设置Chromedriver的启动参数即可解决问题。在启动Chromedriver之前,为Chrome开启实验性功能参数excludeSwitches,它的值为['enable-automation'],完整代码如下:...原创 2021-06-02 17:11:35 · 1729 阅读 · 0 评论 -
chrome版本更新后,chromedriver对应版本更新
chrome浏览器版本更新后,chromedriver对应版本也应对应更新。更新后的chrome版本为版本 90.0.4430.93(正式版本) (64 位)下载对应版本的chromedriver软件对应的win版本只有32位,可以通用下载解压后在python安装目录替换为新下载的chromedriver.exe更新后,程序可以正常使用。...原创 2021-05-06 23:41:17 · 2304 阅读 · 0 评论 -
报错PermissionError: [Errno 13] Permission denied: ‘5101.csv‘
报错PermissionError: [Errno 13] Permission denied: '5101.csv'一般来说,是写入的文件处于打开状态,文件禁止写入。关闭打开的要写入文件即可原创 2021-02-23 11:17:09 · 322 阅读 · 0 评论 -
向DataFrame中添加一列或多列的方法
一、直接添加代码:import pandas as pdtest1 = pd.DataFrame([[1, 2, 3, 4], [2, 3, 4, 5], [3, 4, 5, 6], [4, 5, 6, 7]],columns=list('ABCD')) #print(test1)test1['E']=[6,7,8,9]print(test1)二、通过concat函数添加import pandas as pdtest1 = pd.DataFrame([[1, 2.原创 2021-02-20 10:49:37 · 11948 阅读 · 0 评论 -
使用DataFrame建表的三种方式
import numpy as npimport pandas as pdtest_1 = pd.DataFrame(np.random.rand(4, 4), index=list('ABCD'), columns=list('1234')) # 产生随机数,index行,columns列test_2 = pd.DataFrame([[1, 2, 3, 4], [2, 3, 4, 5], [3, 4, 5, 6], [4, 5, 6, 7]], .转载 2021-02-19 20:20:24 · 1902 阅读 · 0 评论 -
python pandas.DataFrame.loc函数使用详解
官方函数DataFrame.locAccess a group of rows and columns by label(s) or a boolean array..loc[] is primarily label based, but may also be used with a boolean array.# 可以使用label值,但是也可以使用布尔值Allowed inputs are: # 可以接受单个的label,多个label的列表,多个label的切片 A single转载 2021-02-19 11:59:32 · 4420 阅读 · 0 评论 -
python列表中查找最后一个非0值
查找列表中最后一位非0值测试代码df=pd.read_csv('123.csv')arr=list(enumerate(df['test']))print(arr)list=df['test']print(list)ls = [i for i, j in enumerate(list) if j!=0]print(ls)print(ls[-1])输出结果原创 2021-02-17 23:48:17 · 2130 阅读 · 0 评论 -
pycharm不能弹出“figure”窗口的问题
pycharm不能弹出“figure”窗口的问题打开"file"——"settings"找到python scientific 将右边的√去掉原创 2021-02-09 23:28:14 · 1948 阅读 · 0 评论 -
talib如何安装方法
一、在命令行直接使用自动安装命令pip instal TA-lib出现错误,错误如下:二、手动安装安装包下载地址:https://www.lfd.uci.edu/~gohlke/pythonlibs/查找安装包下载对应安装包提示:"successfully installed ta-lib-0.4.19"安装完成。...原创 2021-02-08 15:51:38 · 1155 阅读 · 0 评论 -
module ‘urllib‘ has no attribute ‘urlopen‘
python3.6中引用urllib应写为import urllib.request,不写request容易报错原创 2020-12-19 21:04:43 · 276 阅读 · 1 评论 -
Chrome版本与chromedriver兼容版本对照表
所有版本chromedriver下载http://chromedriver.storage.googleapis.com/index.html所有版本chrome下载:http://www.slimjet.com/chrome/google-chrome-old-version.phphttp://google_chrome.en.downloadastro.com/old_versions/http://filehippo.com/zh/download_google_chrom.原创 2020-10-26 22:24:01 · 3167 阅读 · 0 评论 -
报错selenium.common.exceptions.SessionNotCreatedException: Message: session not created: This version
上周还好好的,两天没运行,运行直接报错selenium.common.exceptions.SessionNotCreatedException: Message: session not created: This version of ChromeDriver only supports Chrome version 74初步判断为chromedriver版本与chrome版本不兼容所导致尝试升级chromedriver版本试试...原创 2020-10-26 22:13:03 · 512 阅读 · 0 评论 -
‘utf-8‘ codec can‘t decode byte 0xc6 in position 7: invalid continuation byte
在python中打开txt文件,报错如下:UnicodeDecodeError: 'utf-8' codec can't decode byte 0xc6 in position 7: invalid continuation byte检查文件编码格式为“ANSI”,另存为文件编码为UTF-8,再次运行。正常...原创 2020-10-26 01:01:28 · 2252 阅读 · 1 评论 -
通过tushare获取股票数据
import tushare as tsimport pandas as pda# data=ts.get_hist_data('000510')# print(data)# data.to_excel('j:/stock/list.xlsx')df=ts.get_day_all()df.to_excel('j:/stock/data.xlsx')原创 2020-10-13 20:07:59 · 604 阅读 · 0 评论 -
python decimal与str相互之间转换
1、str转decimalb=u'45'print(type(b))c=decimal.Decimal(b)print(type(c))结果2、decimal转strd=str(c)print(type(d))原创 2020-08-06 09:57:59 · 6015 阅读 · 0 评论 -
graphviz如何将dot文件转为png,pdf的方法
先转到文件的根目录转为png图片dot -Tpng dtc.dot -o dtc.png转为pdf文件dot -Tpdf dtc.dot -o dtc.pdf原创 2020-08-03 13:28:23 · 4396 阅读 · 1 评论 -
Graphviz的安装
打开graphviz官网,进入下载页面:http://www.graphviz.org/download/windows系统选择下载对应版本根据系统版本进行下载下载完成后文件执行安装,按照默认直接点击下一步就行,安装路径自己选择:配置环境变量查看安装版本dot -version安装并没有完成,执行dot -c如果不执行doc -c 运行命令会报如下错误:安装完毕后执行命令PDF文件生成,安装完毕...原创 2020-08-01 23:54:39 · 219 阅读 · 0 评论 -
运行pycharm报错RuntimeError: implement_array_function method already has a docstring
运行pycharm报错RuntimeError: implement_array_function method already has a docstring如下图经查询了解应该是matplotlib版本不匹配,通过pip install matplotlib==3.0.3安装3.0.3版本,替换掉了原版本3.2.1安装完毕后,重新运行程序,正常运行。...原创 2020-07-31 16:03:36 · 729 阅读 · 0 评论 -
报错No module named sklearn cross_validation
No module named 'sklearn.cross_validation'sklearn中已经废弃cross_validation,将其中的内容整合到model_selection中 将sklearn.cross_validation 替换为 sklearn.model_selection原创 2020-06-02 19:19:28 · 1059 阅读 · 0 评论 -
get_hist_data和ts.get_k_data之间的区别
data=ts.get_hist_data('300274')print(data)运行结果df = ts.get_k_data('002415')print(df)运行结果数据类型均为dataframe原创 2020-06-02 13:42:10 · 2596 阅读 · 1 评论 -
在tushare的token如何在pycharm中设置
一、注册账号tushare账号注册地址:https://tushare.pro/register?reg=370131二、登录账号三、查看个人主页四、点击接口TOKEN,点击复制。完成五、使用原创 2020-05-29 19:47:05 · 965 阅读 · 0 评论 -
python报'DataFrame' object has no attribute 'as_matrix'错误
在python中报错'DataFrame' object has no attribute 'as_matrix'解决办法https://pandas.pydata.org/pandas-docs/stable/search.html?q=as_matrixDataFrame.as_matrix is deprecated. Use DataFrame.values instead (GH18458).将as_matrix()替换为values,如果替换为values()原创 2020-05-12 11:17:59 · 3845 阅读 · 4 评论 -
scikitlearn下载地址
https://pypi.org/project/scikit-learn/#files适用版本号主要是3.5——3.8适用mac,linux和win下载时要对应安装环境和python版本,不匹配容易出错。原创 2020-05-07 15:52:17 · 1224 阅读 · 0 评论 -
numpy+mkl下载地址
https://www.lfd.uci.edu/~gohlke/pythonlibs/原创 2020-03-25 12:54:31 · 3153 阅读 · 0 评论 -
TimeoutException错误类的引入
在pycharm中,except TimeoutException中的TimeoutException没有报错,但是在延迟时报错,报错原因是name "TimeoutException" is not defined 。。引入TimeoutException就正常from selenium.common.exceptions import TimeoutException...原创 2019-12-01 23:30:12 · 2098 阅读 · 1 评论 -
python列表对应元素合并为列表
a=['a','aa','aaa','aaaa']b= ['b','bb','bbb','bbbb']d = []for i in range(len(a)): c=[] c.append(a[i]) c.append(b[i]) d.append(c)print(d)a=['a','aa','aaa','aaaa']b= [['b',...原创 2019-11-22 15:05:58 · 2402 阅读 · 0 评论 -
python中元素删除方式pop,del,remove
python中元素删除方式pop,del,remove原创 2019-11-18 19:09:22 · 255 阅读 · 0 评论 -
pyquery元素标签的获取
from pyquery import PyQuery as pyhtml = '''<div class="div1"><ul class="ul1"><li class="li1">this is li1.<span>this is span1.</span></li><li class="li2"&g...原创 2019-11-18 18:38:49 · 1426 阅读 · 0 评论 -
Python3中新函数(gt,ge,eq,le,lt)的意义
gt #意思是greater than(大于)ge #意思是greater and equal(大于等于)eq #意思是equal(等于)le #意思是less and equal(小于等于)lt #意思是less than(小于)ne #不等于————————————————例1(GT):from pyquery import PyQue...原创 2019-11-18 18:25:09 · 6914 阅读 · 0 评论