编程基础
天青色的瓷
AI算法工程师
展开
-
超大json文件拆分
背景:330M的json文件,有大概100w+条数据,内部存在格式问题,需手动替换修改办法:拆分为6个小json文件,代码如下:# 读取大json文件with open('binguan_all.json', 'r', encoding='utf-8') as f1: N = [json.loads(line.strip()) for line in f1.readlines()] # 将数据按照每20w条一份,分别存储 total = len(N)//200000 # 为了原创 2020-09-10 16:13:13 · 6693 阅读 · 2 评论 -
从Mysql数据库中,导出某表的全部columns字段名
问题:数据库里的某个表有几十个字段,如何一次性获取?直接上代码:SELECT column_name FROM information_schema.COLUMNS WHERE table_name = 'score_model_demo';其中“score_model_demo”是我的表名,亲测有效。如果你的问题解决了,欢迎收藏+点赞+关注哦~...原创 2020-08-12 16:33:39 · 1501 阅读 · 0 评论 -
日期时间datetime与时间戳timestamp互相转换
字符串日期时间转换成时间戳# '2015-08-28 16:43:37.283' --> 1440751417def string2timestamp(strValue): d = datetime.datetime.strptime(strValue, "%Y-%m-%d %H:%M:%S") t = d.timetuple() timeStamp = int(time.mktime(t)) timeStamp = float(str(timeStamp)原创 2020-07-21 11:47:32 · 5048 阅读 · 1 评论 -
Mac中设置默认从anaconda路径打开jupyter notebook
背景:近期update了anaconda的所有包,设置了多个虚拟环境。问题:启动terminal后,输入“jupyter notebook”无法打开jupyter,如下:$ jupyter notebook-bash: jupyter: command not found临时解决方案:(激活conda的base环境,下方路径是anaconda的安装路径)$ source ~/anaconda3/bin/activate(base) ccm ~再输入“jupyter notebook”,就原创 2020-06-29 08:50:11 · 2441 阅读 · 0 评论 -
python中numpy.argsort(),将数组按照大小返回其index
A = array([ 0, 0, 0, 0, 2, 0, 0, 0, 2, 0, 0, 0, 0, 0, 0, 0, 0, 13, 0, 0, 3, 0, 0, 0, 0, 0, 0, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 4, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,原创 2020-05-20 14:18:24 · 3487 阅读 · 0 评论 -
Pandas经过groupby聚合变为Series后,经过排序返回值最大的前2项(TOP2)
希望返回values对应为5和4的两项,及其对应的longitude和latitude值df_agg1.groupby(['longitude','latitude'])['foot_mark'].sum()运行以上返回:longitude latitude121.258340 37.493010 5121.259149 37.496940 1121.259180 37.502860 1121.264030 37.487900 4121.302646原创 2020-05-16 12:32:40 · 417 阅读 · 0 评论 -
正则表达式str.extract后多出1列
想extract匹配的项,结果发现返回了2列train.Ticket.str.extract('(([A-Z]+\.?)+\s*\d*)')返回:标题尝试加入 ?: 后,将(?:[A-Z]+.?)看为一个整体,再运行则只返回1列了。train.Ticket.str.extract('((?:[A-Z]+\.?)+\s*\d*)')返回:如果你的问题解决了,欢迎收藏+点赞+关注哦...原创 2020-04-06 14:46:39 · 414 阅读 · 0 评论 -
progressbar进度条在python中的异常和正确使用方法
conda安装progressbar包conda install -c anaconda progressbarprogressbar的导入和应用(出现异常!)import progressbartotal = 10000000bar = progressbar.ProgressBar(maxval=total+1, widgets=[progressbar.Bar('=', '[',...原创 2020-01-20 21:32:36 · 1366 阅读 · 4 评论 -
【解决方法】EOFError:Compressed file ended before the end-of-stream marker was reached
错误原因文件下载中断后,重新下载,或者文件已经下载完成。解决办法删除已经下载的文件,例如运行此代码时出错:testset = datasets.FashionMNIST('~/.pytorch/F_MNIST_data/', download=True, train=False, transform=transform)**则在电脑中搜索“F_MNIST_data”,将该文件夹删除即...原创 2019-11-30 14:34:43 · 5989 阅读 · 0 评论 -
TypeError: unhashable type: 'list'解决办法。
错误原因:因为list、set、dict:是不可哈希的什么意思?举2个不同栗子:例1:list_0 = [1,2,3,4]s = set(list_0)print(s)>>>{1, 2, 3, 4}原创 2019-11-16 16:15:40 · 96193 阅读 · 1 评论 -
from collections import Counter()
计数器Counter()的应用示范:from collections import Counterlist_01 = ['A','C','S','A','B','f','S','A']dict_01 = Counter(list_01)print(dict_01)将会直接输出一个字典,内容是列表中的元素及其出现频数:Counter({'A': 3, 'S': 2, 'C': 1, '...原创 2019-11-16 09:02:23 · 872 阅读 · 0 评论