Python数据挖掘学习02--numpy和pandas模块基本使用
来源:互联网 发布:淘宝店自己可以开吗 编辑:程序博客网 时间:2024/06/13 23:58
一、numpy模块
导入numpy模块并命名为npy
>>> import numpy as npy
1、创建数组
(1)一维数组
>>> x = npy.array(['22','18','15','4'])>>> xarray(['22', '18', '15', '4'],dtype='<U2')>>>
(2)二维数组
>>> y = npy.array([['aa','bb','cc'],['12','14'],['adasd']])>>> yarray([list(['aa', 'bb', 'cc']), list(['12', '14']), list(['adasd'])], dtype=object)>>>
2、数组排序
>>> a = npy.array([15,22,17,6])>>> aarray([15, 22, 17, 6])>>> a.sort()>>> aarray([ 6, 15, 17, 22])>>>
3、取最大值最小值
>>> a = npy.array([15,22,17,6])>>> aarray([15, 22, 17, 6])>>> a.min()6>>> a.max()22
注意:两种情况会取不出最大值最小值的情况
1、数组中有不为数字的项
>>> a = npy.array([['15','22','17','6'],['12','23']]) #不为数字>>> a.min()['12','23'] #就会出现找不出最小数的情况
2、数组同一维度中长度不同也会报错
>>> a = npy.array([[15,22],[7,6,7]]) >>> a.min()[15,22]
4、切片
a[0:2]相当于取a数组中下表为0到2但不包含2下标的数组,也就是说是取a[0],a[1]
>>> a = npy.array([2,3,4,5,1,2,3])>>> aarray([2, 3, 4, 5, 1, 2, 3])>>> a[0:2] #取0~2的数组但不包含2array([2, 3])>>> a[:-1] #取到最后一位,但不包含最后一位array([2, 3, 4, 5, 1, 2])>>> a[1:] #下标为1后的所有数,包含第一一位array([3, 4, 5, 1, 2, 3])>>> a[:] #取所有数array([2, 3, 4, 5, 1, 2, 3])
二、pandas模块
导入pandas模块并命名为pda
>>> import pandas as pda
1、Series:序列
>>> a = pda.Series([1,2,3,4,5])>>> a0 11 22 33 44 5dtype: int64
1、Series:序列
>>> a = pda.Series([1,2,3,4,5])>>> a0 11 22 33 44 5dtype: int64
2、DataFrame:数据框,有行有列
>>> c = pda.DataFrame([[1,2,3],[2,3,4],[3,2,5]])>>> c 0 1 20 1 2 31 2 3 42 3 2 5
(1)取头部或尾部几行
#取头部,默认5行>>> c.head() 0 1 20 1 2 31 2 3 42 3 2 5#取头部2行>>> c.head(2) 0 1 20 1 2 31 2 3 4#取尾部,默认5行>>> c.tail() 0 1 20 1 2 31 2 3 42 3 2 5#取尾部2行>>> c.tail(2) 0 1 21 2 3 42 3 2 5
(2)描述
>>> c.describe() 0 1 2count 3.0 3.000000 3.0mean 2.0 2.333333 4.0std 1.0 0.577350 1.0min 1.0 2.000000 3.025% 1.5 2.000000 3.550% 2.0 2.000000 4.075% 2.5 2.500000 4.5max 3.0 3.000000 5.0
count:每一列的个数
mean:每一列的平均数
(3)反转
>>> c 0 1 20 1 2 31 2 3 42 3 2 5>>> c.T 0 1 20 1 2 31 2 3 22 3 4 5
阅读全文
0 0
- Python数据挖掘学习02--numpy和pandas模块基本使用
- 【Python数据挖掘】实用模块之Pandas
- python数据挖掘包Pandas基本操作
- 【Python数据挖掘课程】六.Numpy、Pandas和Matplotlib包基础知识
- Python数据挖掘课程 六.Numpy、Pandas和Matplotlib包基础知识
- python数据挖掘包numpy基本操作
- Python数据挖掘学习03--pandas模块数据的导入实战
- python中numpy和pandas学习
- Python数据分析模块安装---Numpy、Pandas、Matplotlib
- python数据挖掘02--pandas基础
- python数据分析学习笔记-Numpy-Matplotlib-Pandas
- 《Python数据分析常用手册》一、NumPy和Pandas篇
- Python数据分析常用手册——Numpy和Pandas
- 《Python数据分析常用手册》一、NumPy和Pandas篇
- 《Python数据分析常用手册》一、NumPy和Pandas篇
- 《Python数据分析常用手册》一、NumPy和Pandas篇
- python安装numpy和pandas
- python模块学习pandas(-)
- Redis大部分相关
- NSURLComponents 使用简介
- 批量修改myeclipse项目中已有的htm文件的编码格式
- java反编译工具JD-GUI资源
- 1、redis配置文件参数
- Python数据挖掘学习02--numpy和pandas模块基本使用
- Ubuntu安装JDK详解
- Android逆向系列之动态调试8–IDA调试so文件(下)
- Java Web 2.1.4 HTML 表单标签与表单设计 (实例)
- 解决多表关联转换json内存溢出
- 手写汉字识别数据准备
- 比较两个date返回日期相差天数
- 钱包
- Guava学习笔记:Preconditions优雅的检验参数