文章分类 - python之数据分析
利用python进行数分析实战
摘要:一、数据操作 #数据实操 #pandas读入外部数据 a = pd.read_csv("C:/Users/32403/Desktop/岭回归.csv") print(a) #对数据排序,可以查看最高或者最低数 b = a.sort_values(by="HR",ascending=False) pr
阅读全文
摘要:一、基本数据格式 import pandas as pd import numpy as np import string #pandas常用数据类型包括:series(一维,带标签数组)和DataFrame(二维,Series容器) #创建series t = pd.Series(np.arang
阅读全文
摘要:一、数据转置 t = np.arange(18).reshape(3,6) print(t) print(t.transpose())#转置命令 print(t.swapaxes(1,0)) print(t.T) 二、数据切片与索引 #numpy的索引与切片 print(t[1]) #第一行 pri
阅读全文
摘要:一、 import numpy as np t4 = np.array(range(1,4),dtype = "int8") print(t4) #bool类型 t5 = np.array([1,0,1,0,1],dtype="bool") print(t5) print(t5.dtype) #调整
阅读全文
摘要:一、散点图 整体绘制方法,类似折线图,唯一不同使用scatter方法。 #同一个坐标轴里面绘制两个图形方法,添加拟合曲线 import matplotlib.pyplot as plt from matplotlib import font_manager my_font = font_manage
阅读全文
摘要:一、前面一章已经学习如何绘制折线图,设置一些参数 import matplotlib.pyplot as plt y = [1,0,1,1,2,4,3,2,3,4,4,5,6,5,4,3,3,1,1,1] x = [i for i in range(11,31)] plt.figure(figsiz
阅读全文
摘要:import matplotlib.pyplot as plt fig = plt.figure(figsize= (10,5),dpi=80) x = range(2,26,2) y = [15,13,14.5,17,20,25,26,26,24,22,18,15] plt.plot(x,y) p
阅读全文
摘要:一,列表表达式 举个例子,要生成list [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]可以用list(range(1, 11)): 若要生成102列表,可采用循环生成 r = [] for i in range(10): r.append(i*i) r [0, 1, 4, 9, 1
阅读全文
摘要:一、切片 在元组和列表里面,常见的切片方式。 L = ['Miahel','Saral','Bob','Jack','Tracy'] [L[0],L[1],L[2]] #直接取前三个元素,最笨办法 ['Miahel', 'Saral', 'Bob'] 采用循环方式,挨着取元素 r = [] n =
阅读全文
摘要:一、调用函数 help函数查看函数解释,查看函数功能与参数设置方法,例:help(abs) 1. abs()函数,取绝对值函数 2. max函数,返回所有函数值中最大的那个。 数据类型转换函数,如下: 1.int() 函数,函数对象转换为整数 2.float() 函数,函数对象转换为浮点数数据 3.
阅读全文
摘要:一、字典(dict)——dict的key必须是不可变对象 Python内置了字典:dict的支持,dict全称dictionary,在其他语言中也称为map,使用键-值(key-value)存储,具有极快的查找速度。保存数据以键值对方式存储数据。并且还替换键值对对应值。一个key只能对应一个valu
阅读全文
摘要:一、列表(list) 列表为python的一种数据类型,可以随时删除或添加里面的元素。形式如下: classmates = ['Michael','Bob','Tracy'] classmates ['Michael', 'Bob', 'Tracy'] 看len函数,查看变量的数目。用索引查看具体变
阅读全文
摘要:一、字符串 1.1python支持包含中文的字符串 print("中文很好hellopython“) 中文很好hellopython 1.2单字符编码 Python提供了ord()函数获取字符的整数表示,chr()函数把编码转换为对应的字符: >>> ord('A') 65 >>> ord('中')
阅读全文
摘要:一、整数与浮点数 表示方法与数学上表示方法一致,可正,可负数,若整数过大可以用_连接。浮点数即小数,当用科学计数法表示时,小数点的位置是可以移动的。 整数运算永远是精确的(除法难道也是精确的?是的!),而浮点数运算则可能会有四舍五入的误差。 a = 10 b = 10_000_0000 c = 1.
阅读全文

浙公网安备 33010602011771号