python 找到numpy中等于某个像素值的点坐标 numpy怎么根据值找索引_缺失值


PART 1 知识点练习

一维数据分析

numpy

定义列表:


python 找到numpy中等于某个像素值的点坐标 numpy怎么根据值找索引_缺失值_02


1)索引查询元素:


python 找到numpy中等于某个像素值的点坐标 numpy怎么根据值找索引_缺失值_03


2)切片访问:


python 找到numpy中等于某个像素值的点坐标 numpy怎么根据值找索引_数据_04


3)使用dtype查看数据类型:


python 找到numpy中等于某个像素值的点坐标 numpy怎么根据值找索引_numpy 获取特定数值的索引_05


dtype详细信息参考网址:

Data type objects (docs.scipy.org

4)统计计算功能,如:平均值mean()、标准差std()


python 找到numpy中等于某个像素值的点坐标 numpy怎么根据值找索引_获取值_06


5)向量化运算,如:向量相加、向量乘以标量


python 找到numpy中等于某个像素值的点坐标 numpy怎么根据值找索引_numpy 获取特定数值的索引_07


pandas

定义一维数据结构:


python 找到numpy中等于某个像素值的点坐标 numpy怎么根据值找索引_numpy 获取特定数值的索引_08


1)获取描述统计信息:


python 找到numpy中等于某个像素值的点坐标 numpy怎么根据值找索引_缺失值_09


2)获取值

iloc属性用于根据位置顺序获取值、loc属性用于根据索引获取值


python 找到numpy中等于某个像素值的点坐标 numpy怎么根据值找索引_缺失值_10


3)向量化运算:向量相加

不同的向量相加时,索引不同会导致不相同的索引的数据为空值None


python 找到numpy中等于某个像素值的点坐标 numpy怎么根据值找索引_numpy 获取特定数值的索引_11


4)处理缺失值(空值)

方法2中,fill_valiue=0将空值填充为0,去除缺失值,再将s2与s1相加


python 找到numpy中等于某个像素值的点坐标 numpy怎么根据值找索引_numpy 获取特定数值的索引_12


二维数据分析

numpy

二维数组结构


python 找到numpy中等于某个像素值的点坐标 numpy怎么根据值找索引_数据_13


1)获取元素


python 找到numpy中等于某个像素值的点坐标 numpy怎么根据值找索引_缺失值_14


2)按数轴进行计算


python 找到numpy中等于某个像素值的点坐标 numpy怎么根据值找索引_获取值_15


python 找到numpy中等于某个像素值的点坐标 numpy怎么根据值找索引_数据_16


Pandas:数据框(DataFrame)


python 找到numpy中等于某个像素值的点坐标 numpy怎么根据值找索引_缺失值_17


定义有序的数据框


python 找到numpy中等于某个像素值的点坐标 numpy怎么根据值找索引_缺失值_18


1)平均值计算(按列计算)


python 找到numpy中等于某个像素值的点坐标 numpy怎么根据值找索引_获取值_19


2)获取值

iloc属性用于根据位置顺序获取值


python 找到numpy中等于某个像素值的点坐标 numpy怎么根据值找索引_numpy 获取特定数值的索引_20


loc属性用于根据索引获取值


python 找到numpy中等于某个像素值的点坐标 numpy怎么根据值找索引_numpy 获取特定数值的索引_21


3)复杂查询

切片功能:


python 找到numpy中等于某个像素值的点坐标 numpy怎么根据值找索引_数据_22


条件判断:


python 找到numpy中等于某个像素值的点坐标 numpy怎么根据值找索引_获取值_23


简便写法:


python 找到numpy中等于某个像素值的点坐标 numpy怎么根据值找索引_数据_24


4)查看数据集描述统计信息


python 找到numpy中等于某个像素值的点坐标 numpy怎么根据值找索引_numpy 获取特定数值的索引_25


PART 2 案例实践(朝阳医院2018年销售数据)

数据分析的基本步骤包括:

  • 提出问题
  • 理解数据
  • 数据清洗
  • 构建模型
  • 数据可视化

1.提出问题

从销售数据中分析出以下业务指标: 1)月均消费次数 2)月均消费金额 3)客单价

2. 理解数据

2.1 读取Excel的数据


python 找到numpy中等于某个像素值的点坐标 numpy怎么根据值找索引_数据_26


2.2 查看数据及字段


python 找到numpy中等于某个像素值的点坐标 numpy怎么根据值找索引_获取值_27


3. 数据清洗

3.1 选择子集

所有的列在数据分析中都需要用到,本案例不需要选择子集

3.2 列名重命名


python 找到numpy中等于某个像素值的点坐标 numpy怎么根据值找索引_获取值_28


3.3 缺失数据处理

python缺失值有3种:

1)Python内置的None值

2)在pandas中,将缺失值表示为NA,表示不可用not available。

3)对于数值数据,pandas使用浮点值NaN(Not a Number)表示缺失数据。

后面出来数据,如果遇到错误:说什么foloat错误,那就是有缺失值,需要处理掉

所以,缺失值有3种:None,NA,NaN

dropna函数详细使用地址:

pandas.DataFrame.dropna - pandas 1.1.2 documentationpandas.pydata.org

python 找到numpy中等于某个像素值的点坐标 numpy怎么根据值找索引_numpy 获取特定数值的索引_29


python 找到numpy中等于某个像素值的点坐标 numpy怎么根据值找索引_获取值_30


注:操作后发现没有变化,于是返回打印数据看是否有缺失值


python 找到numpy中等于某个像素值的点坐标 numpy怎么根据值找索引_数据_31


可能原因是:显示看到的nan 实际就是个 'nan'的字符串 替换成NaN就可以删除。


python 找到numpy中等于某个像素值的点坐标 numpy怎么根据值找索引_获取值_32


3.4 数据类型转换

字符串转换为数值(浮点型)


python 找到numpy中等于某个像素值的点坐标 numpy怎么根据值找索引_获取值_33


字符串转换为日期数据类型


python 找到numpy中等于某个像素值的点坐标 numpy怎么根据值找索引_numpy 获取特定数值的索引_34


python 找到numpy中等于某个像素值的点坐标 numpy怎么根据值找索引_数据_35


python 找到numpy中等于某个像素值的点坐标 numpy怎么根据值找索引_数据_36


3.5 数据排序


python 找到numpy中等于某个像素值的点坐标 numpy怎么根据值找索引_numpy 获取特定数值的索引_37


python 找到numpy中等于某个像素值的点坐标 numpy怎么根据值找索引_缺失值_38


by:按哪几列排序,ascending=True 表示升序排列,,ascending=True表示降序排列。

na_position=True表示排序的时候,把空值放到前列,这样可以比较清晰的看到哪些地方有空值。

官网文档:

https://pandas.pydata.org/pandas-docs/stable/generated/pandas.DataFrame.sort_values.htmlpandas.pydata.org


重命名index


python 找到numpy中等于某个像素值的点坐标 numpy怎么根据值找索引_numpy 获取特定数值的索引_39


3.6 异常值处理


python 找到numpy中等于某个像素值的点坐标 numpy怎么根据值找索引_获取值_40


最小值中有负数,删除


python 找到numpy中等于某个像素值的点坐标 numpy怎么根据值找索引_缺失值_41


4. 构建模型

4.1 求月均消费次数

月均消费次数=总消费次数 / 月份数


python 找到numpy中等于某个像素值的点坐标 numpy怎么根据值找索引_数据_42


python 找到numpy中等于某个像素值的点坐标 numpy怎么根据值找索引_numpy 获取特定数值的索引_43


4.2 求月均消费金额


python 找到numpy中等于某个像素值的点坐标 numpy怎么根据值找索引_numpy 获取特定数值的索引_44


4.3 求客单价


python 找到numpy中等于某个像素值的点坐标 numpy怎么根据值找索引_数据_45