![](https://img-blog.csdnimg.cn/20201014180756916.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
Python
roamer314
这个作者很懒,什么都没留下…
展开
-
为OSM地图建立网络拓扑关系,导出shp文件
为OSM地图建立网络拓扑关系,导出shp文件原创 2023-03-02 19:23:06 · 961 阅读 · 1 评论 -
解决时序数据pandas groupby 按时间分组后0值填充的问题
针对时序数据按不同时间粒度统计时,如果粒度比较小比如15min会存在统计值为0,而pandas返回的dataframe默认只显示结果为非0的记录,如果此时需要填充,可以使用.unstack(fill_value=0).stack()原创 2023-03-02 11:02:22 · 563 阅读 · 0 评论 -
pandas groupby agg lambda分组多列筛选统计数量
pandas groupby agg lambda分组多列筛选统计数量原创 2023-02-23 08:59:51 · 1196 阅读 · 0 评论 -
pandas groupby agg多列重命名
使用pandas groupby对多列进行计算后自动重命名。原创 2022-09-14 19:16:58 · 2396 阅读 · 0 评论 -
Proxy_Pool 代理池与Redis配置的常见问题
问题1:ERROR redis connection error: Error 10061 connecting to 127.0.0.1:6379. 由于目标计算机积极拒绝,无法连接。解决:下载并安装Redis-x64-3.0.504.msi或zip都行,地址:https://github.com/MicrosoftArchive/redis/releases问题2:redis中redis.exceptions.AuthenticationError: Authentication require原创 2022-04-19 22:09:20 · 1053 阅读 · 0 评论 -
jupyterlab 插件安装
conda install -c conda-forge jupyterlab-variableinspectorconda install -c conda-forge jupyterlab_execute_timeNote: for this to show anything, you need to enable cell timing in the notebook via Settings->Advanced Settings Editor->Notebook: {"rec原创 2021-11-17 09:49:31 · 873 阅读 · 0 评论 -
geopandas 离线安装
Python Extension Packages for Windows - Christoph Gohlke (uci.edu)在这个网站下载以下whl文件,然后用pipinstall命令依次安装whl文件gdal fiona shapely pyproj geopandas原创 2021-10-06 10:59:18 · 494 阅读 · 1 评论 -
spyder删除默认变量
删除spyder变量浏览器(Variable Explore)中的默认变量,例如pi, e, euler_gamma, cast, ScalarType等Tools > Preferences > IPython console > Graphics > Automatically load Pylab and NumPy modules原创 2021-09-23 20:48:47 · 451 阅读 · 0 评论 -
jupyterlab插件
jupyterlab-spreadsheet jupyterlab-spreadsheet帮助我们在jupyter lab中查看表格类文件,特别是其支持查看多工作表的excel表格文件jupyterlab-system-monitor jupyterlab-system-monitor通过在jupyter lab界面中添加资源监视器部件,能帮助我们在工作过程中方便的看到CPU、内存的实时占用情况jupyterlab-kite 这个插件我们之前的文章仔细介绍过,帮助我们建立代码补..原创 2021-09-16 19:54:25 · 608 阅读 · 0 评论 -
pandas中文时间格式转换
31-3月 -18 11.24.01.000000000 上午格式转为标准时间格式首先使用apply函数将“上午”、“下午”替换:(lambda x:str(x).replace('.000000000 上午',' AM'))然后使用pd.to_datetime函数转化为时间格式 (data['col'], format="%d-%m月 -%y %I.%M.%S %p")format参考https://www.dataindeendent.com/pandas/pandas-to-...原创 2021-08-16 19:22:00 · 1235 阅读 · 0 评论 -
pandas按半小时区间分组统计
data.groupby(['col',data.START_HOUR.dt.floor('30Min')]).size().reset_index()原创 2021-08-16 19:14:34 · 1273 阅读 · 0 评论 -
pandas将数据按5分钟平均
详见https://stackoverflow.com/questions/36681945/group-dataframe-in-5-minute-intervals原创 2020-11-16 21:45:21 · 1267 阅读 · 0 评论 -
手动安装geopandas
在安装geopandas之前,需要安装Shapely、GDAL、Fiona、geopy,前三个可以去https://www.lfd.uci.edu/~gohlke/pythonlibs/#lxml下载原创 2020-11-14 15:51:40 · 177 阅读 · 0 评论 -
利用multiprocessing对pandas的apply并行加速,非groupby操作
import pandas as pdfrom multiprocessing import Poolfrom functools import partialdef dosomething(row): #添加计算操作 return def parallelize(data, func, num_of_processes=8): data_split = np.array_split(data, num_of_processes) poo.原创 2020-09-13 07:30:59 · 2687 阅读 · 0 评论 -
python 离线安装依赖包
新建文件夹,打开cmdpip download 包名拷贝到另外一台电脑pip install --no-index --find-links=文件夹路径 包名原创 2020-06-12 00:53:38 · 214 阅读 · 0 评论 -
pandas 将多个dataframe进行merge
pandas 将多个dataframe进行mergeimport pandas as pdfrom functools import reducedfs = [df1, df2, df3]df_final = reduce(lambda left,right: pd.merge(left,right,on='col',how='left'), dfs)原创 2020-06-21 02:06:00 · 5663 阅读 · 5 评论 -
使用multiprocessing Pool 对 pandas groupby apply加速
1.multiprocessing Pool 的使用import multiprocessingdef func(args): # do something return df #返回一个dfif __name__ == "__main__": pool = multiprocessing.Pool() result=pd.DataFrame() result=result.append(pool.map(func,list) ) #给func传..原创 2020-06-14 14:13:41 · 2503 阅读 · 0 评论 -
pandas pivot 不等长的多列
pandas pivot 不等长的pd.concat([pd.DataFrame({g:d.B.tolist()}) for g,d in df.groupby('A')], axis=1)原创 2020-06-11 01:59:52 · 363 阅读 · 0 评论 -
使用list循环填充pandas series
使用list循环填充pandas seriesfrom itertools import cycleseq = cycle([1, 2, 3])df['Seq'] = [next(seq) for count in range(df.shape[0])]原创 2020-06-10 19:16:52 · 620 阅读 · 0 评论 -
pandas apply加速
使用map速度比apply快def func(S1, S2): #do something return #data['similarity'] =pd.Series()data['similarity'] = list(map(func,data['col1'], data['col2']))#data['similarity'] = data.apply(lambda row: func(row['col1'], row['col2']), axis=1)...原创 2020-06-07 02:48:25 · 1112 阅读 · 0 评论 -
Keras training progress bar 打印新的一行问题
Keras verbose training progress bar writing a new line on each batch issue解决办法:命令行宽度太窄了,把命令行拉宽点。。。原创 2020-05-31 21:34:27 · 348 阅读 · 0 评论 -
tensorflow 2.X Failed to load the native TensorFlow runtime 问题解决
ImportError: DLL load failed: The specified module could not be found.Failed to load the native TensorFlow runtime.解决办法:Go to theMicrosoft Visual C++ downloads,Scroll down the page to the Visual Studio 2015, 2017 and 2019 section.Download and inst.原创 2020-05-31 21:32:11 · 4560 阅读 · 0 评论 -
离线安装tensorflow-1.15.3所需要的依赖包
λ pip install "C:\Users\Administrator\Desktop\tf\tensorflow-1.15.3-cp37-cp37m-win_amd64.whl"Processing c:\users\administrator\desktop\tf\tensorflow-1.15.3-cp37-cp37m-win_amd64.whlRequirement already satisfied: google-pasta>=0.1.6 in c:\anaconda3\lib\s原创 2020-05-30 16:32:46 · 3312 阅读 · 0 评论 -
pandas groupby apply 并行处理
from joblib import Parallel, delayeddef processParallel(df,name): #处理数据,如果不加name,return的data没有group信息 return datadef applyParallel(dfGrouped, func): retLst = Parallel(n_jobs=6)(delayed(func)(group,name) for name, group in dfGrouped) ret..原创 2020-05-29 20:29:36 · 2923 阅读 · 0 评论 -
pandas 按频率排序
order=staypoint['label'].value_counts().reset_index() #统计频率order=order.apply(lambda row: row.name, axis=1) #按出现频率从高到低赋索引值areamap=dict(order[['index','label']].values.tolist())#生成dictstaypoint['label']=staypoint['label'].map(areamap) #赋值...原创 2020-05-29 20:23:48 · 1912 阅读 · 0 评论 -
GridSearchCV调参
from sklearn import datasetsfrom sklearn.model_selection import train_test_splitfrom sklearn.model_selection import GridSearchCVfrom sklearn.metrics import classification_reportfrom sklearn.svm i...原创 2020-03-18 19:44:56 · 501 阅读 · 0 评论 -
pandas查找出dataframe中任意一个字段含有空值的一行
pandas查找出dataframe中任意一个字段含有空值的一行df[df.isnull().T.any()]原创 2020-03-10 16:39:07 · 1627 阅读 · 0 评论 -
解决Microsoft Visual C++ 14.0 is required 以及 'cl.exe' 相关问题
使用pip安装package时报错:1. Microsoft Visual C++ 14.0 is required.2.'cl.exe' failed: No such file or directory3. 'cl.exe' failed with exit status可使用以下方式解决:1. 安装Visual Studio的最新版Build Tools (https:...原创 2019-11-23 18:50:09 · 953 阅读 · 1 评论 -
conda环境管理
查看当前存在哪些虚拟环境conda env list 创建python版本为X.X、名字为your_env_name的虚拟环境conda create -n your_env_name python=X.X激活虚拟环境。activate your_env_name(虚拟环境名称)对虚拟环境中安装额外的包conda install -n your_env_nam...原创 2019-11-23 18:27:33 · 100 阅读 · 0 评论 -
解决RuntimeError: b'no arguments in initialization list' 问题
使用geopandas进行坐标系转换时,报错RuntimeError: b'no arguments in initialization list' 问题是由proj造成的,可以通过更新proj修复pip install --ignore-installed pyproj==2.4.0...原创 2019-11-02 17:20:35 · 1765 阅读 · 1 评论 -
pandas 删掉空行
df=df[~(df['col'].isnull())] #删掉空行df=dropna(axis=0) #删除有空值的行,使用参数axis=0df=dropna(axis=1) #删除有空值的列,使用参数axis=1原创 2018-12-05 08:48:41 · 22796 阅读 · 4 评论 -
Unable to acquire Oracle environment handle
报错: InterfaceError: Unable to acquire Oracle environment handleinstantclient_11_2下的dll文件放入python的\Lib\site-packages文件下如果还不行,尝试cmd或者spyder用管理员执行原创 2016-08-23 20:13:29 · 922 阅读 · 0 评论 -
解决read_csv读取中文文件名、路径报错OSError: Initializing from file failed问题
pandas read_csv直接读取含中文的文件名(或者中文路径)会报错OSError: Initializing from file failed解决办法:f= open(r"中文路径")df= pd.read_csv(f)原创 2019-09-27 15:59:17 · 324 阅读 · 0 评论 -
usecols选取指定列rename修改列名round指定有效位数
"""Created on Tue May 9 20:35:45 2017usecols选取指定列rename 修改列名round 指定有效位数@author: PC"""import pandas as pddata=pd.read_csv(r"D:\datasource\taxi_gps\TaxiRes_2015-05-18.c原创 2017-05-09 20:58:39 · 1333 阅读 · 0 评论 -
pandas groupby count按小时统计交易量
import pandas as pddata=pd.read_csv(r'C:\Users\lenovo\Desktop\TaxiRes_2015-05-08.csv')data.groupby(data['Time']).count()原创 2017-03-09 20:01:31 · 8680 阅读 · 0 评论 -
python 代理IP
#encoding=utf8import requestsfrom urllib.request import urlopenfrom bs4 import BeautifulSoupsession=requests.Session()User_Agent = 'Mozilla/5.0 (Windows NT 6.3; WOW64; rv:43.0) Gecko/20100101 Fir原创 2016-10-17 08:15:50 · 664 阅读 · 0 评论 -
python dbscan算法
import pylab as plfrom collections import defaultdict,Counterpoints = [[float(eachpoint.split(",")[0]), float(eachpoint.split(",")[1])] for eachpoint in open(r"E:\Users\Desktop\points.txt","r")]# 计原创 2016-10-17 08:13:21 · 4085 阅读 · 2 评论 -
python连接oracle数据库
import cx_Oracleimport pandas as pd#引用模块cx_Oracle'''conn=cx_Oracle.connect('XXX/XXX@172.18.49.XXX:1521/orcl') #连接数据库c=conn.cursor() #获取cursorx=c.exe...原创 2016-10-13 01:25:36 · 1419 阅读 · 0 评论 -
pandas三列数关联匹配
import pandas as pddata=pd.read_excel('20161002.xlsx')D1=set(data.D201606)D2=set(data.D201512)D3=set(data.D201506)D4=set(data.D201501)D=list(D1&D2&D3&D4)result=pd.DataFrame(columns=['NAME','R原创 2016-10-12 18:52:08 · 3803 阅读 · 0 评论 -
pandas连接数据库
from sqlalchemy import create_engineengine = create_engine('oracle://passwords:passwords@172.18.49.193:1521/orcl')原创 2016-10-12 18:48:32 · 1919 阅读 · 0 评论