前言:Python数据分析的基础在于对数据的提取,清洗,汇总,并思考整理发现数据规律的过程。以下模块是个人在数据分析常用模块,特此总结,便于查阅,构建数据分析体系。
数据源
导入数据
查看、检查数据DataFrame较为常见,DataFrame的生成可通过读取纯文本、Json等数据来生成,亦可以通过Python对象来生成
selectSelect ONE,THREE from df where index >= 1 and index<= 3 order by index
Select * from df where index >= 1 and index < 3 order by index
Select ONE,THREE from df
WHEREPandas实现where filter,较为常用的办法为df[df[colunm] boolean expr]
SELECT * from df where ONE > 1.1
AND
OR
IN
NOT
LIKE
某列是否包含字符.str.contains('str')
select case when ONE like '字符' then -1 else 0 end from df
DISTINCT保留重复元素中的第一个,删除重复元素的后面列
df.drop_duplicates(subset=['ONE'], keep='first', inplace=False)
1. subset,为选定的列做distinct&