06 2018 档案
摘要:# -*- coding: utf-8 -*-"""Created on Sat Jun 30 14:49:22 2018 @author: zhen""" import numpy as npa = np.array([[1,2,3],[11,22,33]])b = np.array([[4,5,
阅读全文
摘要:# -*- coding: utf-8 -*-"""Created on Sat Jun 30 11:49:56 2018 @author: zhen"""# 测试排列组合 import itertools# 定义测试数据list_test = [1,2,3,4,5]# 定义结果数据list_res
阅读全文
摘要:# -*- coding: utf-8 -*-"""Created on Sat Jun 30 10:09:47 2018测试分组groupby@author: zhen"""from pandas import DataFrame"""data = [ [1,2,2,1] [2,2,2,2] [1
阅读全文
摘要:# 去除重复行数据 keep:'first':保留重复行的第一行,'last':保留重复行的最后一行,False:删除所有重复行df = df.drop_duplicates( subset=['YJML','EJML','SJML','WZLB','GGXHPZ','CGMS'], # 去重列,按
阅读全文
摘要:df = pd.merge( df, # 左 wzplbm, # 右 left_on = ['WZBM','ZBWZMC'], # 左DataFrame匹配列 right_on = ['WZPLBM','WZMC'],# 右DataFrame匹配列 how='inner' # 内连接 (left:左
阅读全文
摘要:# 创建空DataFrame df = pd.DataFrame(columns = ['YJML','EJML','SJML','WZLB','GGXHPZ','CGMS']) # 插入数据(忽略索引) df = df.append(kjcgml.loc[i].append(bzwzcgml.lo
阅读全文
摘要:# 文件路径 file_path = 'C:/Users/zhen/Desktop/物资/ycsj.xlsx' ycsj = pd.read_excel( file_path, # 文件路径 sheet_name='2018年物资类采购目录--资料', # 读取Excel中某个sheet的数据,没有
阅读全文
摘要:# 在Python中可以根据某列的具体内容来拆分数据,保存成多个DataFrame! # 代码如下: ycsj = pfsj[pfsj['备注'].isin(['1'])] # 拆分数据: 结果:
阅读全文
摘要:# 识别python中DataFrame中的nanfor i in pfsj.index: if type(pfsj.loc[i]['WZML']) == float: print('float value is ${}'.format(pfsj.loc[i]['WZML'])) elif type
阅读全文
摘要:一.概述 参考博客:https://www.cnblogs.com/yszd/p/8529704.html 二.代码实现【解析解】 三.结果【解析解】 可视化: 四.代码实现【sklearn机器学习库】 五.结果【sklearn机器学习库】 可视化: 六.总结 根据图示可以得出结论,使用解析解或者是
阅读全文
摘要:#coding:utf-8from sklearn.datasets import load_irisfrom sklearn.model_selection import train_test_splitfrom sklearn.neighbors import KNeighborsClassifierimport numpy as npimport matplotlib.pyplot as p...
阅读全文
摘要:# NumPy Python科学计算基础包 import numpy as np # 导入numpy库并起别名为npnumpy_array = np.array([[1,3,5],[2,4,6]])print(numpy_array) # SciPy Python中用于科学计算的函数集合from s
阅读全文
摘要:# 使用默认的高阶函数map和reduce import randomdef map_function(arg): # 生成测试数据 return (arg,1) list_map = list(map(map_function,list(ran * random.randint(1,2) for
阅读全文
摘要:# 测试参数是传值还是传引用def test(arg): print("test before") print(id(arg)) arg[1]=30 # 测试可变对象 # arg[3][2] = 16 # 测试嵌套类型 # arg = list(range(5)) print("test after
阅读全文
摘要:# 练习迭代器# Iterable可迭代的,像:list,dict,set,tuple,str等都可以迭代from collections import Iterableprint(isinstance([], Iterable))print(isinstance({}, Iterable))pri
阅读全文
摘要:#练习使用生成器print("杨辉三角效果图:")def triangles(max): n=1 T=[1] yield T while n < max: T=[1]+[T[i-1]+T[i] for i in range(1,n)]+[1] #print("before step ...") yi
阅读全文
摘要:一.概述 高阶函数,就是一个函数可以接收另一个函数作为参数的函数,scala与之类似。 二.导入基础包 import random from functools import reduce 三.自定义高阶函数 #定义普通函数,自动生成列表 def getList(): hList = list(ra
阅读全文
摘要:一.isinstance&type isinstance()函数用来判断一个对象是否是一个已知类型的数据,类似于type()。 isinstance()和type()的区别: 1.type()不会认为子类是一种父类类型,不考虑继承关系。 2.isinstance()会认为子类是一种父类类型,考虑继承
阅读全文
摘要:import math #测试循环numbers = ["one","two","three"] #定义列表for number in numbers:#遍历,测试for循环 print("number is : " + number)#使用for循环和基本列表创建新列表values = list(
阅读全文
摘要:#"""学习和测试条件控制(单独使用和嵌套使用)"""#在prompt和jupyter中多行注释都无效#测试单独使用name = input("place input you name : ")#默认传入的是stringmid = input("place input you age : ")if
阅读全文
摘要:类是一些有共同特征和行为事务事物的抽象概念的总和。 从中可以看出,方法只能使用实例直接调用(无需传self参数),而使用类调用必须传入实例对象; 属性可以使用实例调用,也可以使用类直接调用,因此可以看出,其实self就是实例本身,在实例调用方法时传入。 被实例化的对象会被编译器默默的传入方法的括号中
阅读全文