python数据分析总结(pandas)

目录

前言

df导入数据

df基本增删改查

数据清洗

​编辑

索引操作

数据统计

行列操作

​编辑

df->types

数据格式化

​编辑

日期数据处理


前言

此篇文章为个人python数据分析学习总结,总结内容大都为表格和结构图方式,仅供参考。

df导入数据

类型 语法
xls、xlsx pd.read_excel(io、sheet_name、index_col)
csv/txt pd.read_csv(filepath_or_buffer、encoding、sep、delimiter、index_col)
html pd.read_html(io、match、index_col、encoding) 注意io不支持https
mysql pd.read_sql(sql、con、index_col)

df基本增删改查

数据清洗

索引操作

方法 描述
reindex(index,columns,axis,fill_value,method) 使用指定行列序列值来设置索引(行或列)
set_index(col_names,drop) 使用已存在的列来设置索引
reset_index(drop) 重新设置索引

数据统计

注意:以下axis:0(列)、axis:1(行)

方法 描述
sort_values(by,ascending,inplace) 根据指定列来排序数据
rank(ascending,method) 对数据记录进行排序
value_counts(ascending,dropna) 对数据中的值进行计数
sum() 求和
mean() 平均值
max() 最大值
min() 最小值
median() 中位数
mode() 众数
var() 方差
quantile() 分位数
groupby(by) 分组
agg(agg_funcs) 聚合方法
agg(agg_dict) 聚合

行列操作

df->types

转换类型 方法
df -> dict df.to_dict()
df -> list df.values.tolist()
df -> tuple tuple(x) for x in df.values

数据格式化

日期数据处理

相关推荐
花酒锄作田16 小时前
Pydantic校验配置文件
python
hboot16 小时前
AI工程师第四课 - 深度学习入门
pytorch·python·神经网络
ZhengEnCi1 天前
P2M-Matplotlib折线图完全指南-从数据可视化到趋势分析的Python绘图利器
python·matlab·数据可视化
ZhengEnCi1 天前
P2L-Matplotlib饼图完全指南-从数据可视化到图表定制的Python绘图利器
python·matlab
曲幽1 天前
你的REST接口还在“过度投喂”数据吗?——FastAPI + GraphQL实战避坑指南
python·fastapi·web·graphql·route·cors·rest·strawberry
用户8358086187911 天前
基于 Self-RAG 与列表级重排序的进阶 RAG 系统设计与实现
python
Warson_L2 天前
Python `Annotated` 与 LangGraph Reducer 学习笔记
python
韩师傅2 天前
海天线算法的前世今生
python·计算机视觉
韩师傅2 天前
当你的甲方设备过烂,要如何快速出效果?
python·计算机视觉
Warson_L2 天前
LangGraph的MessageState and HumanMessage
python