pandas numpy模块

首先安装搭建好jupyter notebook,运行成功后的截图如下:

安装使用步骤(PS:确定Python安装路径和安装路径里面Scripts文件夹路径已经配置到环境变量中去,即pip所在路径已经配置到环境变量中去):

//以下说明是在Windows环境下
//安装
pip install jupyter notebook //不出意外即可安装成功
//然后在Scripts文件夹里面即可看到安装后的jupyter notebook相关配置文件 在CMD中输入jupyter notebook即可在默认浏览器中打开jupyter notebook网页编辑页面

推荐资料:

Jupyter Notebook简洁教程

Pandas 使用教程 1

Pandas 使用教程 2

Pandas 使用教程 3

Pandas 使用教程 4

Pandas 使用教程 5


2 peewee模块

使用peewee连接mysql数据库,进行增删查改操作语句示例。原文链接


单条增加 方法1 StudentsInfo.create(student_name='amos', student_no=880) 方法2 StudentsInfo.insert(student_name='lucy', student_no=881).execute() 等同于insert into student_info (student_name, student_no) values ('lee',882) 多条增加 方法1 data_source = [ {'student_name': 'lance', 'student_no': 883}, {'student_name': 'john', 'student_no': 884}, # ... ] for data_dict in data_source: StudentsInfo.create(**data_dict) 方法2(这个方法会快很多) data_source = [ {'student_name': 'jason', 'student_no': 886}, {'student_name': 'tom', 'student_no': 887}, # ... ] with database.atomic(): for data_dict in data_source: StudentsInfo.create(**data_dict) 方法3(最快的方法) data_source = [ {'student_name': 'hom', 'student_no': 888}, {'student_name': 'baby', 'student_no': 889}, # ... ] with database.atomic(): StudentsInfo.insert_many(data_source).execute() 如果数据量太大或许你需要分开处理,比如一次处理100条: data_source = [ {'student_name': 'hom', 'student_no': 888}, {'student_name': 'baby', 'student_no': 889}, # ... ] with database.atomic(): for idx in range(0,len(data_source),100): StudentsInfo.insert_many(data_source[idx:idx+100]).execute() 删
单条删除 st = StudentsInfo.get(student_name='hom') st.delete_instance() 等同于DELETE from student_info where student_name = 'hom' 多条删除 StudentsInfo.delete().where(StudentsInfo.student_no < 883).execute() 等同于DELETE from student_info where student_no < 883 改
方法1指定数据 StudentsInfo.update(student_no=890).where(StudentsInfo.student_name == 'baby').execute() 方法2依据原有数据自动更新 StudentsInfo.update(student_no=StudentsInfo.student_no + 1).where(StudentsInfo.student_name == 'baby').execute() 方法3 多字段更新 StudentsInfo.update(student_no=890,student_name='lady').where(StudentsInfo.student_name == 'baby').execute() 查
1. 一般查询 st1 = StudentsInfo.select() 查询所有的记录并获取他们 for i in st1: print i.student_no, i.student_name 2. 单条查询 st2 = StudentsInfo.get(StudentsInfo.student_no == 883) print st2.student_no, st2.student_name 对比1和2个区别 先获取他们的类型 print type(st1) == > <class 'peewee.SelectQuery'> Print type(st2) == > <class 'createDB.StudentsInfo'> st1是’SelectQuery'类型需要使用for循环逐条获取,而st2本身就是一个实例的对象可以直接获取它的属性 3. 查询部分字段 st3 = StudentsInfo.select(StudentsInfo.student_no) 4. 有条件查询 st4 = StudentsInfo.select().where(StudentsInfo.student_no == 883) 5. 随机查询 需要先引入fn from peewee import fn st5 = StudentsInfo.select().order_by(fn.Random()).limit(2) 6. 排序查询 正序 st6 = StudentsInfo.select().order_by(StudentsInfo.student_no.asc()) 反序 st6 = StudentsInfo.select().order_by(StudentsInfo.student_no.desc()) 7. Not in组合查询 简单举例,现有学生信息表student_info学生姓名student_name和学号student_no,学生成绩表score_table学号student_no和分数score st7 = StudentsInfo.select(StudentsInfo.student_no).where(StudentsInfo.student_no > 880) sc = StudentsScore.select().where(StudentsScore.student_no.not_in(st7)) 8. 模糊查询 比如想要查询学生名字包含’ba’的学生以及学号 %符号就相当于sql里的like st8 = StudentsInfo.select().where(StudentsInfo.student_name % '%ba%') for i in st8: print i.student_no,i.student_name 纯手打,多谢支持。

peewee连接mysql进行增删查改操作

Python有关模块学习记录的更多相关文章

  1. "利用python进行数据分析"学习记录01

    "利用python进行数据分析"学习记录 --day01 08/02 与书相关的资料在 http://github.com/wesm/pydata-book pandas 的2名字 ...

  2. python - argparse 模块学习

    python - argparse 模块学习 设置一个解析器 使用argparse的第一步就是创建一个解析器对象,并告诉它将会有些什么参数.那么当你的程序运行时,该解析器就可以用于处理命令行参数. 解 ...

  3. python paramiko模块学习分享

    python paramiko模块学习分享 paramiko是用python语言写的一个模块,遵循SSH2协议,支持以加密和认证的方式,进行远程服务器的连接.paramiko支持Linux, Sola ...

  4. Python logging 模块学习

    logging example Level When it's used Numeric value DEBUG Detailed information, typically of interest ...

  5. Python time模块学习

    Python time模块提供了一些用于管理时间和日期的C库函数,由于它绑定到底层C实现,因此一些细节会基于具体的平台. 一.壁挂钟时间 1.time() time模块的核心函数time(),它返回纪 ...

  6. 【Python】模块学习之利用string模块造测试数据

    背景 测试过程中需要一些随机数据,使用到了python中的string模块,记录一下 #! /usr/bin/python # coding:utf-8 """ @aut ...

  7. python logging模块学习(转)

    前言 日志是非常重要的,最近有接触到这个,所以系统的看一下Python这个模块的用法.本文即为Logging模块的用法简介,主要参考文章为Python官方文档,链接见参考列表. 另外,Python的H ...

  8. python os模块学习

    一.os模块概述 Python os模块包含普遍的操作系统功能.如果你希望你的程序能够与平台无关的话,这个模块是尤为重要的. 二.常用方法 1.os.name 输出字符串指示正在使用的平台.如果是wi ...

  9. python atexit模块学习

    python atexit模块 只定义了一个register模块用于注册程序退出时的回调函数,我们可以在这个函数中做一下资源清理的操作 注:如果程序是非正常crash,或者通过os._exit()退出 ...

随机推荐

  1. git 删除远程分支和本地分支

    删除远程分支和本地分支 https://www.cnblogs.com/luosongchao/p/3408365.html 将远程git仓库里的指定分支拉取到本地(本地不存在的分支) https:/ ...

  2. 将hta包装为exe发布

    hta在打开的时候,有时候会被杀毒软件拦截而不给执行,更重要的一点是通常都可以右击查看源代码,里面如果涉及到域名或者其它的一些细节就很容易被其它人了解. 网络上有一些hta转exe的,类似的软件基本上 ...

  3. java转义符和正则表达式转义符

    举例来说,连续相同的3位数字的正则表达式的标准语法是: ([\d])\1{2} 但是如果在java代码中这么写,就会出现语法错误,如下: String regEx = "([\d])\1{2 ...

  4. 深入理解java虚拟机(六)字节码指令简介

    Java虚拟机指令是由(占用一个字节长度.代表某种特定操作含义的数字)操作码Opcode,以及跟随在其后的零至多个代表此操作所需参数的称为操作数 Operands 构成的.由于Java虚拟机是面向操作 ...

  5. python3.7新增关键字:async、await;带来和kafka-python==1.4.2的兼容性问题

    python3.7新增关键字:async.await: kafka-python==1.4.2用到了关键字async,由此带来兼容性问题 解决方案: 升级kafka-python==1.4.4 使用p ...

  6. APPLE框架之高效便捷的Repository解决方案

    原文地址:http://perfy315.iteye.com/blog/1460226 Spring Data JPA 转至:http://note.sdo.com/u/855924134/n/P15 ...

  7. ASP.NET Razor 简介

    ylbtech-.NET: ASP.NET Razor 简介 Razor 不是一种编程语言.它是服务器端的标记语言. 1. 什么是 Razor?返回顶部 Razor 是一种标记语法,可以让您将基于服务 ...

  8. 第二章 微服务网关基础组件 - zuul入门

    一.zuul简介 1.作用 zuul使用一系列的filter实现以下功能 认证和安全 - 对每一个resource进行身份认证 追踪和监控 - 实时观察后端微服务的TPS.响应时间,失败数量等准确的信 ...

  9. $.getJSON的缓存问题处理

    今天遇到jQuery.getJSON的缓存问题.如果其调用的url之前曾经调用过的话,回调函数就会直接在缓存里面取得想要得值,而不是进入到后台,调用存储过程了.这是一个比较郁闷的问题.不修改的话,用户 ...

  10. c++字符串split 函数实现

    - 经常遇到字符串分割问题,但是相对于c++而言实现比较麻烦,直接遍历一遍也很冗余 - 另外也适用于,在字符串中找到某个字符的所有位置 //函数功能:将输入字符串s,以字符串c(;)进行拆分,拆分结果 ...