随笔分类 -  Python

摘要:1.Pandas概述 Pandas是Python的一个数据分析包,该工具为解决数据分析任务而创建。 Pandas纳入大量库和标准数据模型,提供高效的操作数据集所需的工具。 Pandas提供大量能使我们快速便捷地处理数据的函数和方法。 Pandas是字典形式,基于NumPy创建,让NumPy为中心的应 阅读全文
posted @ 2020-07-03 17:31 tooltime 阅读(4688) 评论(0) 推荐(0) 编辑
摘要:Python3解释器中内置了69个常用函数,属于底层的函数,它们到处可用,是新手学习的重要内容。 当然,有些函数对大家来说比较熟悉,比如abs(), max(), sum()... 也有一些比较陌生,比如locals(), all(), compile(), getattr()... 今天按照类别扼 阅读全文
posted @ 2020-06-18 15:09 tooltime 阅读(680) 评论(0) 推荐(0) 编辑
摘要:1. txt文件 (1) 单位矩阵,即主对角线上的元素均为1,其余元素均为0的正方形矩阵。在NumPy中可以用eye函数创建一个这样的二维数组,我们只需要给定一个参数,用于指定矩阵中1的元素个数。例如,创建3×3的数组: import numpy as np I2 = np.eye(3) print 阅读全文
posted @ 2020-06-12 16:44 tooltime 阅读(669) 评论(0) 推荐(0) 编辑
摘要:简介f-string,亦称为格式化字符串常量(formatted string literals),是Python3.6新引入的一种字符串格式化方法,该方法源于PEP 498 – Literal String Interpolation,主要目的是使格式化字符串的操作更加简便。f-string在形式 阅读全文
posted @ 2020-05-27 16:26 tooltime 阅读(24955) 评论(1) 推荐(0) 编辑
摘要:这个函数很简单,就不写例子了,看看语法,拿来即用 python range() 函数可创建一个整数列表,一般用在 for 循环中。 函数语法 range(start, stop[, step]) 参数说明: start: 计数从 start 开始。默认是从 0 开始。例如range(5)等价于ran 阅读全文
posted @ 2020-05-27 16:00 tooltime 阅读(870) 评论(0) 推荐(0) 编辑
摘要:一、Python可切片对象的索引方式 Python可切片对象的索引方式包括:正索引和负索引两部分。如下图所示,以a = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]为例: 二、Python切片操作的一般方式 一个完整的切片表达式包含两个“:”,用于分隔三个参数(start_index 阅读全文
posted @ 2020-05-26 18:19 tooltime 阅读(1658) 评论(0) 推荐(0) 编辑
摘要:析构函数:__del__() 释放对象是自动调用 class Person(object): def run(self): print("run") def eat(self, food): print("eat" + food) def __init__(self,name,age,height, 阅读全文
posted @ 2020-05-26 18:06 tooltime 阅读(643) 评论(0) 推荐(0) 编辑
摘要:1.之前的写法(不报错):data = cursor.fetchall()data_name = data[0]['task_type'] 2.简洁的写法(报错):data = cursor.fetchall()[0]['task_type'] 用 2 的写法报错之后,一度怀疑是数据库出了问题。不服 阅读全文
posted @ 2020-05-26 18:03 tooltime 阅读(1931) 评论(0) 推荐(0) 编辑
摘要:导入模块 import pymysql 连接(看一下password有没有,没有的话会怎么样,有很多参数,有些参数也是可以不传的) conn = pymysql.connect(user = "root",host = "127.0.0.1",port = 3306,charset = "utf8" 阅读全文
posted @ 2020-05-26 18:00 tooltime 阅读(292) 评论(0) 推荐(0) 编辑
摘要:正文 描述 Python find() 方法从字符串中找出某个子字符串第一个匹配项的索引位置,该方法与 index() 方法一样,只不过如果子字符串不在字符串中不会报异常,而是返回-1。 语法 find() 方法语法: S.find(sub[,start=0[,end=len(S)]]) 参数 su 阅读全文
posted @ 2020-05-26 17:53 tooltime 阅读(2325) 评论(0) 推荐(0) 编辑
摘要:enumerate()是python的内置函数enumerate在字典上是枚举、列举的意思对于一个可迭代的(iterable)/可遍历的对象(如列表、字符串),enumerate将其组成一个索引序列,利用它可以同时获得索引和值enumerate多用于在for循环中得到计数例如对于一个seq,得到: 阅读全文
posted @ 2020-05-26 16:37 tooltime 阅读(833) 评论(0) 推荐(0) 编辑
摘要:#Python3中已取消iteritems()方法 描述 Python 字典 items() 方法以列表形式(并非直接的列表,若要返回列表值还需调用list函数)返回可遍历的(键, 值) 元组数组。 语法 items() 方法语法: D.items() 参数 无。 返回值 以列表形式返回可遍历的(键 阅读全文
posted @ 2020-05-26 16:05 tooltime 阅读(1013) 评论(0) 推荐(0) 编辑
摘要:# -*- coding: utf-8 -*- """ @description: xxx @time: 2019/12/22 1:03 @author: baojinlong """ import random import time import datetime import pymysql 阅读全文
posted @ 2020-05-26 15:58 tooltime 阅读(348) 评论(0) 推荐(0) 编辑
摘要:情况1:在一个目录下面只有文件,没有文件夹,这个时候可以使用os.listdir 在我们的桌面上有一个file目录(文件夹),里面有三个文件 file(dir)| --|test1.txt --|test2.txt --|test3.txt 用下面的程序获得文件的绝对路径: import os pa 阅读全文
posted @ 2020-04-28 17:13 tooltime 阅读(1195) 评论(0) 推荐(0) 编辑
摘要:python3 中采用 in 方法 1 #判断字典中某个键是否存在 2 arr = {"int":"整数","float":"浮点","str":"字符串","list":"列表","tuple":"元组","dict":"字典","set":"集合"} 3 #使用 in 方法 4 if "int" 阅读全文
posted @ 2020-04-27 19:20 tooltime 阅读(5211) 评论(0) 推荐(0) 编辑
摘要:#创建一个空字典 empty_dict = dict() print(empty_dict) #用**kwargs可变参数传入关键字创建字典 a = dict(one=1,two=2,three=3) print(a) #传入可迭代对象 b = dict(zip(['one','two','thre 阅读全文
posted @ 2020-04-27 19:17 tooltime 阅读(970) 评论(0) 推荐(0) 编辑
摘要:一下文件执行将产生乱码,切.log文件显示问好,打不开 import logging def shop_logging(name): name = name+"登录成功!" logger = logging.getLogger() fh = logging.FileHandler("test.log 阅读全文
posted @ 2020-04-27 19:13 tooltime 阅读(1110) 评论(0) 推荐(0) 编辑
摘要:问题解决方法: 阅读全文
posted @ 2020-04-27 18:14 tooltime 阅读(958) 评论(0) 推荐(0) 编辑
摘要:很多人认为python中的字典是无序的,因为它是按照hash来存储的,但是python中有个模块collections(英文,收集、集合),里面自带了一个子类 OrderedDict,实现了对字典对象中元素的排序。请看下面的实例: import collections print "Regular 阅读全文
posted @ 2020-04-26 14:58 tooltime 阅读(3134) 评论(0) 推荐(0) 编辑
摘要:os.walk方法,主要用来遍历一个目录内各个子目录和子文件。 os.walk(top, topdown=True, onerror=None, followlinks=False) 可以得到一个三元tupple(dirpath, dirnames, filenames), 第一个为起始路径,第二个 阅读全文
posted @ 2020-04-26 14:12 tooltime 阅读(539) 评论(0) 推荐(0) 编辑

点击右上角即可分享
微信分享提示