当前位置:首页>python>Pandas入门到精通|Python数据分析必备技能

Pandas入门到精通|Python数据分析必备技能

  • 2026-07-02 16:54:39
Pandas入门到精通|Python数据分析必备技能

📌 导读:本文将详细介绍Pandas数据分析库,通过学习本文你将掌握Pandas的核心概念和实用技能。文章内容涵盖Series、DataFrame对象创建和操作,文件导入导出,列操作、筛选、排序、分组、合并,数据类型转换,索引等多个方面,配有丰富的代码实例,帮助读者快速上手并在实际项目中灵活运用。

📋 目录

  1. 🔰 Pandas介绍
  2. 📦 Series对象
  3. 📊 DataFrame对象
  4. 📁 文件导入与写入
  5. 🛠️ 列基本操作
  6. 🔢 数据运算
  7. 🔍 数据筛选
  8. 📈 数据排序
  9. 📑 数据分组
  10. 🔗 数据合并与拆分
  11. 🔄 数据类型转换
  12. 📌 索引操作
  13. ✅ 总结与练习

🔰 Pandas介绍

什么是Pandas

Pandas是Python中最强大的数据处理和分析库之一,它提供了快速、灵活、易用的数据结构,使数据清洗和分析变得简单高效。Pandas由Wes McKinney在2008年开发,现已成为数据科学领域的核心工具。

Pandas主要包含两个核心数据结构:

  • Series:一维标签数组,能够保存任何数据类型
  • DataFrame:二维标签数据结构,可以理解为一张Excel表格

💡 提示:Pandas的名字来源于"Panel Data"(面板数据)和"Python Data Analysis"(Python数据分析)的缩写。

Pandas的核心优势

  • 🚀 数据处理能力强:轻松处理缺失数据、数据对齐、数据重塑等复杂操作
  • 📊 灵活的数据结构:支持多种数据格式,方便数据整合
  • ⚡ 高性能:底层基于NumPy,处理速度快
  • 🔧 丰富的函数库:内置大量统计分析函数
  • 📁 文件读写方便:支持多种文件格式的导入导出

安装Pandas

# 使用pip安装Pandas
$ pip install pandas

# 使用conda安装
$ conda install pandas

# 验证安装
$ python -c "import pandas as pd; print(pd.__version__)"

📦 Series对象

Series创建

Series是一维数组,由索引和数据组成。我们可以通过多种方式创建Series。

# 示例1:从列表创建Series
# 文件:create_series.py

import pandas as pd
import numpy as np

# 从列表创建Series
s1 = pd.Series([13579])
print("Series1:")
print(s1)
print()

# 从列表创建,指定索引
s2 = pd.Series([13579], index=['a''b''c''d''e'])
print("Series2(指定索引):")
print(s2)
print()

# 从字典创建Series
data = {'apple'5'banana'3'orange'8'grape'12}
s3 = pd.Series(data)
print("Series3(从字典创建):")
print(s3)
print()

# 从NumPy数组创建
arr = np.array([1020304050])
s4 = pd.Series(arr, index=['p1''p2''p3''p4''p5'])
print("Series4(从NumPy数组创建):")
print(s4)

Series基本操作

# 示例2:Series基本操作
# 文件:series_operations.py

import pandas as pd

# 创建示例数据
data = {'apple'5'banana'3'orange'8'grape'12}
s = pd.Series(data)

# 查看索引
print("索引:", s.index)
print()

# 查看值
print("值:", s.values)
print()

# 通过索引访问
print("apple的值:", s['apple'])
print()

# 通过位置访问
print("第2个位置的值:", s[1])
print()

# 切片操作
print("前3个元素:")
print(s[:3])
print()

# 条件筛选
print("大于5的元素:")
print(s[s > 5])
print()

# 运算操作
print("每个元素乘2:")
print(s * 2)
print()

# 求平方
print("每个元素的平方:")
print(s ** 2)

Series索引

# 示例3:Series索引操作
# 文件:series_index.py

import pandas as pd

# 创建示例数据
s = pd.Series([1020304050], index=['a''b''c''d''e'])
print("原始Series:")
print(s)
print()

# 重新索引
s_reindex = s.reindex(['c''a''e''d''b''f'])
print("重新索引后:")
print(s_reindex)
print()

# 填充缺失值
s_fill = s.reindex(['c''a''e''d''b''f'], fill_value=0)
print("填充缺失值后:")
print(s_fill)
print()

# 使用方法填充
s_ffill = s.reindex(['c''a''e''d''b''f'], method='ffill')
print("前向填充后:")
print(s_ffill)

📊 DataFrame对象

DataFrame创建

DataFrame是二维数据结构,由行和列组成,类似于Excel表格。

# 示例4:DataFrame创建
# 文件:create_dataframe.py

import pandas as pd
import numpy as np

# 从字典创建(最常用)
data = {
'姓名': ['张三''李四''王五''赵六''钱七'],
'年龄': [2530283522],
'城市': ['北京''上海''广州''深圳''杭州'],
'薪资': [1500020000180002500012000]
}
df1 = pd.DataFrame(data)
print("DataFrame1(从字典创建):")
print(df1)
print()

# 指定列顺序
df2 = pd.DataFrame(data, columns=['姓名''城市''年龄''薪资'])
print("DataFrame2(指定列顺序):")
print(df2)
print()

# 指定行索引
df3 = pd.DataFrame(data, index=['a''b''c''d''e'])
print("DataFrame3(指定行索引):")
print(df3)
print()

# 从列表字典创建
data_list = [
    {'姓名''张三''年龄'25'城市''北京'},
    {'姓名''李四''年龄'30'城市''上海'},
    {'姓名''王五''年龄'28'城市''广州'}
]
df4 = pd.DataFrame(data_list)
print("DataFrame4(从列表字典创建):")
print(df4)
print()

# 从NumPy二维数组创建
arr = np.random.randn(53)
df5 = pd.DataFrame(arr, columns=['A''B''C'], index=['行1''行2''行3''行4''行5'])
print("DataFrame5(从NumPy数组创建):")
print(df5)

DataFrame基本属性

# 示例5:DataFrame基本属性
# 文件:dataframe_attributes.py

import pandas as pd

# 创建示例数据
data = {
'姓名': ['张三''李四''王五''赵六''钱七'],
'年龄': [2530283522],
'城市': ['北京''上海''广州''深圳''杭州'],
'薪资': [1500020000180002500012000]
}
df = pd.DataFrame(data)

print("DataFrame形状(行, 列):", df.shape)
print()

print("DataFrame列名:", df.columns.tolist())
print()

print("DataFrame索引:", df.index.tolist())
print()

print("DataFrame数据类型:")
print(df.dtypes)
print()

print("DataFrame维度:", df.ndim)
print()

print("DataFrame元素总数:", df.size)

DataFrame查看数据

# 示例6:DataFrame查看数据
# 文件:dataframe_view.py

import pandas as pd
import numpy as np

# 创建稍大的示例数据
np.random.seed(42)
data = {
'产品ID': range(121),
'产品名称': [f'产品{i}'for i in range(121)],
'销量': np.random.randint(100100020),
'价格': np.random.uniform(5050020).round(2),
'利润': np.random.uniform(1010020).round(2)
}
df = pd.DataFrame(data)

# 查看前5行(默认)
print("前5行数据:")
print(df.head())
print()

# 查看前10行
print("前10行数据:")
print(df.head(10))
print()

# 查看后5行
print("后5行数据:")
print(df.tail())
print()

# 查看后3行
print("后3行数据:")
print(df.tail(3))
print()

# 查看数据基本信息
print("数据基本信息:")
print(df.info())
print()

# 查看数据统计信息(数值列)
print("数据统计信息:")
print(df.describe())

🎯 经验:在实际项目中,数据量通常很大,使用head()和tail()可以快速查看数据结构,info()可以了解数据完整性,describe()可以获得数据的统计概况。


📁 文件导入与写入

读取Excel文件

# 示例7:读取Excel文件
# 文件:read_excel.py

import pandas as pd

# 读取Excel文件(需要openpyxl或xlrd库)
# 首先创建一个示例Excel文件
data = {
'姓名': ['张三''李四''王五''赵六''钱七'],
'年龄': [2530283522],
'城市': ['北京''上海''广州''深圳''杭州'],
'薪资': [1500020000180002500012000]
}
df = pd.DataFrame(data)

# 先写入Excel文件
df.to_excel('employees.xlsx', sheet_name='Sheet1', index=False)
print("Excel文件已创建: employees.xlsx")
print()

# 读取Excel文件
df_read = pd.read_excel('employees.xlsx')
print("读取的Excel数据:")
print(df_read)
print()

# 读取指定工作表
df_sheet = pd.read_excel('employees.xlsx', sheet_name='Sheet1')
print("读取指定工作表:")
print(df_sheet)
print()

# 读取指定行数
df_head = pd.read_excel('employees.xlsx', nrows=3)
print("读取前3行:")
print(df_head)

写入Excel文件

# 示例8:写入Excel文件
# 文件:write_excel.py

import pandas as pd
import numpy as np

# 创建示例数据
data1 = {
'产品': ['A''B''C''D''E'],
'销量': [100200150300250]
}
data2 = {
'日期': ['2024-01-01''2024-01-02''2024-01-03'],
'销售额': [10000120009000]
}

df1 = pd.DataFrame(data1)
df2 = pd.DataFrame(data2)

# 写入单个工作表
df1.to_excel('single_sheet.xlsx', sheet_name='销量数据', index=False)
print("单个工作表Excel已创建: single_sheet.xlsx")
print()

# 写入多个工作表(需要使用ExcelWriter)
with pd.ExcelWriter('multi_sheet.xlsx'as writer:
    df1.to_excel(writer, sheet_name='销量数据', index=False)
    df2.to_excel(writer, sheet_name='日销售额', index=False)
print("多工作表Excel已创建: multi_sheet.xlsx")

读取CSV文件

# 示例9:读取CSV文件
# 文件:read_csv.py

import pandas as pd

# 首先创建一个示例CSV文件
data = {
'姓名': ['张三''李四''王五''赵六''钱七'],
'年龄': [2530283522],
'城市': ['北京''上海''广州''深圳''杭州'],
'薪资': [1500020000180002500012000]
}
df = pd.DataFrame(data)
df.to_csv('employees.csv', index=False, encoding='utf-8-sig')
print("CSV文件已创建: employees.csv")
print()

# 读取CSV文件
df_read = pd.read_csv('employees.csv')
print("读取的CSV数据:")
print(df_read)
print()

# 读取带分隔符的文件(使用sep参数)
df_sep = pd.read_csv('employees.csv', sep=',')
print("指定分隔符读取:")
print(df_sep)
print()

# 读取指定列
df_cols = pd.read_csv('employees.csv', usecols=['姓名''薪资'])
print("读取指定列:")
print(df_cols)

写入CSV文件

# 示例10:写入CSV文件
# 文件:write_csv.py

import pandas as pd

# 创建示例数据
data = {
'商品ID': [12345],
'商品名称': ['笔记本''手机''平板''耳机''键盘'],
'库存': [5010030200150],
'价格': [500030002000500300]
}
df = pd.DataFrame(data)

# 写入CSV文件(不保存索引)
df.to_csv('products.csv', index=False, encoding='utf-8-sig')
print("CSV文件已创建: products.csv")
print()

# 写入CSV文件(指定分隔符)
df.to_csv('products_tab.csv', index=False, sep='\t', encoding='utf-8-sig')
print("Tab分隔CSV已创建: products_tab.csv")

读取TXT文件

# 示例11:读取TXT文件
# 文件:read_txt.py

import pandas as pd

# 首先创建一个示例TXT文件
data = {
'学生姓名': ['小明''小红''小刚''小丽'],
'数学': [85907892],
'英语': [88859087],
'语文': [80958288]
}
df = pd.DataFrame(data)
df.to_csv('scores.txt', index=False, sep=' ', encoding='utf-8')
print("TXT文件已创建: scores.txt")
print()

# 读取TXT文件(使用read_table或read_csv)
df_read = pd.read_table('scores.txt', sep=' ')
print("读取的TXT数据:")
print(df_read)
print()

# 使用read_csv读取
df_csv = pd.read_csv('scores.txt', sep=' ')
print("使用read_csv读取:")
print(df_csv)

写入TXT文件

# 示例12:写入TXT文件
# 文件:write_txt.py

import pandas as pd

# 创建示例数据
data = {
'日期': ['2024-01-01''2024-01-02''2024-01-03''2024-01-04'],
'访问量': [1500200018002200],
'订单数': [50655872]
}
df = pd.DataFrame(data)

# 写入TXT文件
df.to_csv('data.txt', index=False, sep='\t', encoding='utf-8')
print("TXT文件已创建: data.txt")

🛠️ 列基本操作

选择列

# 示例13:选择列
# 文件:select_columns.py

import pandas as pd

# 创建示例数据
data = {
'姓名': ['张三''李四''王五''赵六''钱七'],
'年龄': [2530283522],
'城市': ['北京''上海''广州''深圳''杭州'],
'薪资': [1500020000180002500012000],
'部门': ['技术''销售''技术''产品''运营']
}
df = pd.DataFrame(data)

# 选择单列(方式1)
print("选择单列(方式1):")
print(df['姓名'])
print()

# 选择单列(方式2)
print("选择单列(方式2):")
print(df.姓名)
print()

# 选择多列
print("选择多列:")
print(df[['姓名''薪资''部门']])
print()

# 使用iloc按位置选择列
print("使用iloc选择前3列:")
print(df.iloc[:, 0:3])
print()

# 使用loc按列名选择列
print("使用loc选择指定列:")
print(df.loc[:, ['姓名''城市']])

添加列

# 示例14:添加列
# 文件:add_columns.py

import pandas as pd

# 创建示例数据
data = {
'姓名': ['张三''李四''王五''赵六''钱七'],
'年龄': [2530283522],
'城市': ['北京''上海''广州''深圳''杭州'],
'薪资': [1500020000180002500012000]
}
df = pd.DataFrame(data)
print("原始DataFrame:")
print(df)
print()

# 添加固定值的列
df['部门'] = '技术'
print("添加部门列后:")
print(df)
print()

# 添加计算列
df['年薪'] = df['薪资'] * 12
print("添加年薪列后:")
print(df)
print()

# 添加条件列
df['薪资等级'] = ['高'if x > 20000else'中'if x > 15000else'低'for x in df['薪资']]
print("添加薪资等级列后:")
print(df)
print()

# 使用insert在指定位置插入列
df.insert(2'性别', ['男''男''男''女''女'])
print("在第3列位置插入性别列后:")
print(df)

删除列

# 示例15:删除列
# 文件:delete_columns.py

import pandas as pd

# 创建示例数据
data = {
'姓名': ['张三''李四''王五''赵六''钱七'],
'年龄': [2530283522],
'城市': ['北京''上海''广州''深圳''杭州'],
'薪资': [1500020000180002500012000],
'部门': ['技术''销售''技术''产品''运营'],
'年薪': [180000240000216000300000144000]
}
df = pd.DataFrame(data)
print("原始DataFrame:")
print(df)
print()

# 删除单列(返回新DataFrame,不修改原数据)
df_drop1 = df.drop('年薪', axis=1)
print("删除年薪列后:")
print(df_drop1)
print()

# 删除多列
df_drop2 = df.drop(['部门''年薪'], axis=1)
print("删除部门和年薪列后:")
print(df_drop2)
print()

# 使用inplace参数直接修改原DataFrame
df_copy = df.copy()
df_copy.drop('年薪', axis=1, inplace=True)
print("使用inplace删除后:")
print(df_copy)

列位置互换

# 示例16:列位置互换
# 文件:swap_columns.py

import pandas as pd

# 创建示例数据
data = {
'A': [12345],
'B': [678910],
'C': [1112131415],
'D': [1617181920]
}
df = pd.DataFrame(data)
print("原始DataFrame:")
print(df)
print()

# 交换两列位置
cols = df.columns.tolist()
cols[0], cols[1] = cols[1], cols[0]  # 交换A和B
df_swap = df[cols]
print("交换A和B列后:")
print(df_swap)
print()

# 重新排列所有列顺序
df_reorder = df[['D''C''B''A']]
print("重新排列列顺序后:")
print(df_reorder)
print()

# 将指定列移到最前面
col_name = 'C'
cols = [col_name] + [col for col in df.columns if col != col_name]
df_front = df[cols]
print("将C列移到最前面:")
print(df_front)

列重命名

# 示例17:列重命名
# 文件:rename_columns.py

import pandas as pd

# 创建示例数据
data = {
'Name': ['张三''李四''王五''赵六'],
'Age': [25302835],
'City': ['北京''上海''广州''深圳'],
'Salary': [15000200001800025000]
}
df = pd.DataFrame(data)
print("原始DataFrame:")
print(df)
print()

# 使用rename方法重命名列
df_rename = df.rename(columns={
'Name''姓名',
'Age''年龄',
'City''城市',
'Salary''薪资'
})
print("重命名后:")
print(df_rename)
print()

# 直接修改columns属性
df_copy = df.copy()
df_copy.columns = ['姓名''年龄''城市''薪资']
print("直接修改columns后:")
print(df_copy)

🔢 数据运算

列之间运算

# 示例18:列之间运算
# 文件:column_operations.py

import pandas as pd

# 创建示例数据
data = {
'产品': ['A''B''C''D''E'],
'销量': [100200150300250],
'单价': [5030402535],
'成本': [3020251522]
}
df = pd.DataFrame(data)
print("原始数据:")
print(df)
print()

# 计算销售额 = 销量 * 单价
df['销售额'] = df['销量'] * df['单价']
print("计算销售额后:")
print(df)
print()

# 计算利润 = 销量 * (单价 - 成本)
df['利润'] = df['销量'] * (df['单价'] - df['成本'])
print("计算利润后:")
print(df)
print()

# 计算利润率 = 利润 / 销售额
df['利润率'] = df['利润'] / df['销售额']
print("计算利润率后:")
print(df)

应用函数

# 示例19:应用函数
# 文件:apply_functions.py

import pandas as pd
import numpy as np

# 创建示例数据
data = {
'A': [12345],
'B': [1020304050],
'C': [100200300400500]
}
df = pd.DataFrame(data)
print("原始数据:")
print(df)
print()

# 使用apply对每列应用函数
print("每列求和:")
print(df.apply(np.sum))
print()

print("每列求平均值:")
print(df.apply(np.mean))
print()

# 使用apply对每行应用函数
print("每行求和:")
print(df.apply(np.sum, axis=1))
print()

# 使用自定义函数
defsquare(x):
return x ** 2

print("对每个元素平方:")
print(df.applymap(square))
print()

# 使用lambda函数
print("对每列求最大值减最小值:")
print(df.apply(lambda x: x.max() - x.min()))

统计计算

# 示例20:统计计算
# 文件:statistics.py

import pandas as pd
import numpy as np

# 创建示例数据
np.random.seed(42)
data = {
'数学': np.random.randint(6010010),
'英语': np.random.randint(6010010),
'语文': np.random.randint(6010010),
'物理': np.random.randint(6010010)
}
df = pd.DataFrame(data)
print("学生成绩数据:")
print(df)
print()

# 基本统计量
print("均值:")
print(df.mean())
print()

print("中位数:")
print(df.median())
print()

print("标准差:")
print(df.std())
print()

print("方差:")
print(df.var())
print()

print("最小值:")
print(df.min())
print()

print("最大值:")
print(df.max())
print()

print("总和:")
print(df.sum())
print()

# 相关性分析
print("相关性矩阵:")
print(df.corr())

🔍 数据筛选

条件筛选

# 示例21:条件筛选
# 文件:filter_conditions.py

import pandas as pd

# 创建示例数据
data = {
'姓名': ['张三''李四''王五''赵六''钱七''孙八''周九''吴十'],
'年龄': [2530283522402733],
'城市': ['北京''上海''广州''深圳''杭州''北京''上海''广州'],
'薪资': [1500020000180002500012000300001600022000],
'部门': ['技术''销售''技术''产品''运营''技术''销售''技术']
}
df = pd.DataFrame(data)
print("原始数据:")
print(df)
print()

# 单一条件筛选
print("薪资大于20000的员工:")
print(df[df['薪资'] > 20000])
print()

print("年龄小于30的员工:")
print(df[df['年龄'] < 30])

逻辑运算筛选

# 示例22:逻辑运算筛选
# 文件:filter_logic.py

import pandas as pd

data = {
'姓名': ['张三''李四''王五''赵六''钱七''孙八''周九''吴十'],
'年龄': [2530283522402733],
'城市': ['北京''上海''广州''深圳''杭州''北京''上海''广州'],
'薪资': [1500020000180002500012000300001600022000],
'部门': ['技术''销售''技术''产品''运营''技术''销售''技术']
}
df = pd.DataFrame(data)

# AND运算(&)
print("在北京工作且薪资大于20000的员工:")
print(df[(df['城市'] == '北京') & (df['薪资'] > 20000)])
print()

# OR运算(|)
print("在技术部门或销售部门的员工:")
print(df[(df['部门'] == '技术') | (df['部门'] == '销售')])
print()

# NOT运算(~)
print("不在广州工作的员工:")
print(df[~(df['城市'] == '广州')])

isin筛选

# 示例23:isin筛选
# 文件:filter_isin.py

import pandas as pd

data = {
'姓名': ['张三''李四''王五''赵六''钱七''孙八''周九''吴十'],
'年龄': [2530283522402733],
'城市': ['北京''上海''广州''深圳''杭州''北京''上海''广州'],
'薪资': [1500020000180002500012000300001600022000],
'部门': ['技术''销售''技术''产品''运营''技术''销售''技术']
}
df = pd.DataFrame(data)

# 使用isin筛选
cities = ['北京''上海''深圳']
print("在北京、上海、深圳工作的员工:")
print(df[df['城市'].isin(cities)])
print()

departments = ['技术''销售']
print("在技术或销售部门的员工:")
print(df[df['部门'].isin(departments)])
print()

# 使用isin的反义
print("不在技术或销售部门的员工:")
print(df[~df['部门'].isin(departments)])

空值处理

# 示例24:空值处理
# 文件:handle_null.py

import pandas as pd
import numpy as np

# 创建包含空值的示例数据
data = {
'姓名': ['张三''李四', np.nan, '赵六''钱七'],
'年龄': [25, np.nan, 283522],
'城市': ['北京''上海''广州', np.nan, '杭州'],
'薪资': [15000200001800025000, np.nan]
}
df = pd.DataFrame(data)
print("包含空值的数据:")
print(df)
print()

# 检查空值
print("每个列的空值数量:")
print(df.isnull().sum())
print()

# 删除包含空值的行
df_dropna = df.dropna()
print("删除空值行后:")
print(df_dropna)
print()

# 填充空值
df_fillna = df.fillna({
'姓名''未知',
'年龄': df['年龄'].mean(),
'城市''未知',
'薪资': df['薪资'].median()
})
print("填充空值后:")
print(df_fillna)

📈 数据排序

按值排序

# 示例25:按值排序
# 文件:sort_values.py

import pandas as pd

# 创建示例数据
data = {
'姓名': ['张三''李四''王五''赵六''钱七''孙八'],
'年龄': [253028352240],
'城市': ['北京''上海''广州''深圳''杭州''北京'],
'薪资': [150002000018000250001200030000]
}
df = pd.DataFrame(data)
print("原始数据:")
print(df)
print()

# 按单升序排序
print("按薪资升序排序:")
print(df.sort_values(by='薪资'))
print()

# 按单降序排序
print("按薪资降序排序:")
print(df.sort_values(by='薪资', ascending=False))

按索引排序

# 示例26:按索引排序
# 文件:sort_index.py

import pandas as pd

# 创建示例数据
data = {
'姓名': ['张三''李四''王五''赵六''钱七'],
'年龄': [2530283522],
'城市': ['北京''上海''广州''深圳''杭州'],
'薪资': [1500020000180002500012000]
}
df = pd.DataFrame(data, index=[31402])
print("原始数据(无序索引):")
print(df)
print()

# 按索引升序排序
print("按索引升序排序:")
print(df.sort_index())
print()

# 按索引降序排序
print("按索引降序排序:")
print(df.sort_index(ascending=False))

多列排序

# 示例27:多列排序
# 文件:sort_multiple.py

import pandas as pd

# 创建示例数据
data = {
'姓名': ['张三''李四''王五''赵六''钱七''孙八''周九''吴十'],
'年龄': [2530283522402733],
'城市': ['北京''上海''广州''深圳''杭州''北京''上海''广州'],
'薪资': [1500020000180002500012000300001600022000]
}
df = pd.DataFrame(data)
print("原始数据:")
print(df)
print()

# 多列排序
print("先按城市升序,再按薪资降序:")
print(df.sort_values(by=['城市''薪资'], ascending=[TrueFalse]))

📑 数据分组

groupby分组

# 示例28:groupby分组
# 文件:groupby.py

import pandas as pd

# 创建示例数据
data = {
'姓名': ['张三''李四''王五''赵六''钱七''孙八''周九''吴十'],
'城市': ['北京''上海''广州''深圳''杭州''北京''上海''广州'],
'部门': ['技术''销售''技术''产品''运营''技术''销售''技术'],
'薪资': [1500020000180002500012000300001600022000],
'年龄': [2530283522402733]
}
df = pd.DataFrame(data)
print("原始数据:")
print(df)
print()

# 按城市分组
city_group = df.groupby('城市')
print("按城市分组的组名:")
print(city_group.groups)
print()

# 查看每个组的大小
print("每个城市的人数:")
print(city_group.size())
print()

# 按部门分组
dept_group = df.groupby('部门')
print("按部门分组:")
for name, group in dept_group:
    print(f"\n部门: {name}")
    print(group)

聚合函数

# 示例29:聚合函数
# 文件:aggregate.py

import pandas as pd

# 创建示例数据
data = {
'姓名': ['张三''李四''王五''赵六''钱七''孙八''周九''吴十'],
'城市': ['北京''上海''广州''深圳''杭州''北京''上海''广州'],
'部门': ['技术''销售''技术''产品''运营''技术''销售''技术'],
'薪资': [1500020000180002500012000300001600022000],
'年龄': [2530283522402733]
}
df = pd.DataFrame(data)

# 按城市分组,计算薪资的统计量
city_stats = df.groupby('城市')['薪资'].agg(['mean''sum''max''min''count'])
print("按城市分组的薪资统计:")
print(city_stats)
print()

# 使用字典为不同列应用不同聚合函数
grouped = df.groupby('部门').agg({
'薪资': ['mean''sum'],
'年龄': ['mean''max'],
'姓名''count'
})
print("按部门分组的多列统计:")
print(grouped)

分组后操作

# 示例30:分组后操作
# 文件:groupby_operations.py

import pandas as pd

# 创建示例数据
data = {
'姓名': ['张三''李四''王五''赵六''钱七''孙八''周九''吴十'],
'城市': ['北京''上海''广州''深圳''杭州''北京''上海''广州'],
'部门': ['技术''销售''技术''产品''运营''技术''销售''技术'],
'薪资': [1500020000180002500012000300001600022000],
'年龄': [2530283522402733]
}
df = pd.DataFrame(data)

# 计算每个城市的薪资平均值,并添加为新列
df['城市平均薪资'] = df.groupby('城市')['薪资'].transform('mean')
print("添加城市平均薪资列:")
print(df)
print()

# 使用apply对分组应用自定义函数
deftop_salary(group):
return group.sort_values('薪资', ascending=False).head(2)

top_employees = df.groupby('部门').apply(top_salary).reset_index(drop=True)
print("每个部门薪资最高的2名员工:")
print(top_employees)

🔗 数据合并与拆分

concat合并

# 示例31:concat合并
# 文件:concat.py

import pandas as pd

# 创建示例数据
df1 = pd.DataFrame({
'姓名': ['张三''李四''王五'],
'年龄': [253028],
'城市': ['北京''上海''广州']
})

df2 = pd.DataFrame({
'姓名': ['赵六''钱七''孙八'],
'年龄': [352240],
'城市': ['深圳''杭州''北京']
})

print("DataFrame1:")
print(df1)
print()

print("DataFrame2:")
print(df2)
print()

# 纵向合并(按行)
df_concat_v = pd.concat([df1, df2], ignore_index=True)
print("纵向合并后:")
print(df_concat_v)
print()

# 创建横向合并的示例数据
df3 = pd.DataFrame({
'薪资': [150002000018000],
'部门': ['技术''销售''技术']
})

# 横向合并(按列)
df_concat_h = pd.concat([df1, df3], axis=1)
print("横向合并后:")
print(df_concat_h)

merge合并

# 示例32:merge合并
# 文件:merge.py

import pandas as pd

# 创建示例数据
df1 = pd.DataFrame({
'员工ID': [12345],
'姓名': ['张三''李四''王五''赵六''钱七'],
'部门ID': [101102101103104]
})

df2 = pd.DataFrame({
'部门ID': [101102103105],
'部门名称': ['技术部''销售部''产品部''运营部'],
'部门地址': ['A栋3楼''A栋5楼''B栋2楼''C栋1楼']
})

print("员工信息:")
print(df1)
print()

print("部门信息:")
print(df2)
print()

# 内连接(inner join)- 只保留匹配的行
df_merge_inner = pd.merge(df1, df2, on='部门ID', how='inner')
print("内连接结果:")
print(df_merge_inner)
print()

# 左连接(left join)- 保留左表所有行
df_merge_left = pd.merge(df1, df2, on='部门ID', how='left')
print("左连接结果:")
print(df_merge_left)
print()

# 右连接(right join)- 保留右表所有行
df_merge_right = pd.merge(df1, df2, on='部门ID', how='right')
print("右连接结果:")
print(df_merge_right)
print()

# 外连接(outer join)- 保留所有行
df_merge_outer = pd.merge(df1, df2, on='部门ID', how='outer')
print("外连接结果:")
print(df_merge_outer)

join合并

# 示例33:join合并
# 文件:join.py

import pandas as pd

# 创建示例数据
df1 = pd.DataFrame({
'姓名': ['张三''李四''王五'],
'年龄': [253028]
}, index=[123])

df2 = pd.DataFrame({
'城市': ['北京''上海''广州'],
'薪资': [150002000018000]
}, index=[124])

print("DataFrame1:")
print(df1)
print()

print("DataFrame2:")
print(df2)
print()

# 使用join进行索引连接
df_join = df1.join(df2, how='left')
print("join连接结果:")
print(df_join)

数据拆分

# 示例34:数据拆分
# 文件:split_data.py

import pandas as pd
import numpy as np

# 创建示例数据
data = {
'姓名': ['张三''李四''王五''赵六''钱七''孙八''周九''吴十''郑十一''王十二'],
'年龄': [25302835224027332931],
'城市': ['北京''上海''广州''深圳''杭州''北京''上海''广州''深圳''杭州'],
'薪资': [15000200001800025000120003000016000220002800019000]
}
df = pd.DataFrame(data)
print("原始数据:")
print(df)
print()

# 按条件拆分
mask = df['薪资'] >= 20000
df_high = df[mask]
df_low = df[~mask]
print("高薪员工(薪资>=20000):")
print(df_high)
print()

print("普通员工(薪资<20000):")
print(df_low)
print()

# 按索引拆分
df_part1 = df.iloc[:5]
df_part2 = df.iloc[5:]
print("第一部分(前5行):")
print(df_part1)
print()

print("第二部分(后5行):")
print(df_part2)

🔄 数据类型转换

查看数据类型

# 示例35:查看数据类型
# 文件:view_dtypes.py

import pandas as pd
import numpy as np

# 创建示例数据
data = {
'姓名': ['张三''李四''王五'],
'年龄': [253028],
'薪资': [15000.520000.018000.75],
'入职日期': ['2020-01-15''2019-05-20''2021-03-10'],
'在职': [TrueTrueFalse]
}
df = pd.DataFrame(data)
print("原始数据:")
print(df)
print()

# 查看数据类型
print("各列数据类型:")
print(df.dtypes)
print()

# 查看数据类型信息
print("数据类型信息:")
print(df.info())

类型转换

# 示例36:类型转换
# 文件:convert_dtypes.py

import pandas as pd
import numpy as np

# 创建示例数据
data = {
'姓名': ['张三''李四''王五'],
'年龄': [25.030.028.0],
'薪资': ['15000''20000''18000'],
'入职日期': ['2020-01-15''2019-05-20''2021-03-10'],
'在职': ['True''True''False']
}
df = pd.DataFrame(data)
print("原始数据:")
print(df)
print()

print("原始数据类型:")
print(df.dtypes)
print()

# 转换薪资为整数
df['薪资'] = df['薪资'].astype(int)

# 转换在职为布尔值
df['在职'] = df['在职'].astype(bool)

# 转换入职日期为datetime
df['入职日期'] = pd.to_datetime(df['入职日期'])

print("转换后的数据类型:")
print(df.dtypes)
print()

print("转换后的数据:")
print(df)

时间类型处理

# 示例37:时间类型处理
# 文件:datetime_handling.py

import pandas as pd
import numpy as np

# 创建示例数据
data = {
'姓名': ['张三''李四''王五''赵六''钱七'],
'入职日期': ['2020-01-15''2019-05-20''2021-03-10''2018-08-25''2022-01-01']
}
df = pd.DataFrame(data)
df['入职日期'] = pd.to_datetime(df['入职日期'])
print("原始数据:")
print(df)
print()

# 提取日期信息
df['年份'] = df['入职日期'].dt.year
df['月份'] = df['入职日期'].dt.month
df['日期'] = df['入职日期'].dt.day
df['星期'] = df['入职日期'].dt.day_name()
df['季度'] = df['入职日期'].dt.quarter

print("提取日期信息后:")
print(df)
print()

# 计算入职天数
today = pd.to_datetime('2024-01-01')
df['入职天数'] = (today - df['入职日期']).dt.days
print("计算入职天数后:")
print(df)

📌 索引操作

设置索引

# 示例38:设置索引
# 文件:set_index.py

import pandas as pd

# 创建示例数据
data = {
'员工ID': [101102103104105],
'姓名': ['张三''李四''王五''赵六''钱七'],
'年龄': [2530283522],
'城市': ['北京''上海''广州''深圳''杭州'],
'薪资': [1500020000180002500012000]
}
df = pd.DataFrame(data)
print("原始数据:")
print(df)
print()

# 设置员工ID为索引
df_index = df.set_index('员工ID')
print("设置索引后:")
print(df_index)
print()

# 使用索引访问数据
print("访问员工ID为103的信息:")
print(df_index.loc[103])

重置索引

# 示例39:重置索引
# 文件:reset_index.py

import pandas as pd

# 创建示例数据
data = {
'姓名': ['张三''李四''王五''赵六''钱七'],
'年龄': [2530283522],
'城市': ['北京''上海''广州''深圳''杭州'],
'薪资': [1500020000180002500012000]
}
df = pd.DataFrame(data, index=[101102103104105])
print("带有自定义索引的数据:")
print(df)
print()

# 重置索引(默认将原索引作为新列)
df_reset1 = df.reset_index()
print("重置索引后(保留原索引):")
print(df_reset1)
print()

# 重置索引(不保留原索引)
df_reset2 = df.reset_index(drop=True)
print("重置索引后(不保留原索引):")
print(df_reset2)

多层索引

# 示例40:多层索引
# 文件:multi_index.py

import pandas as pd
import numpy as np

# 创建示例数据
data = {
'销量': [100150200120180220],
'利润': [50751006090110]
}
index = pd.MultiIndex.from_product([
    ['北京''上海''广州'],
    ['第一季度''第二季度']
], names=['城市''季度'])
df_multi = pd.DataFrame(data, index=index)
print("多层索引数据:")
print(df_multi)
print()

# 访问多层索引数据
print("访问北京的数据:")
print(df_multi.loc['北京'])
print()

print("访问北京第一季度的数据:")
print(df_multi.loc[('北京''第一季度')])

✅ 总结与练习

核心要点回顾

通过本文的学习,相信你已经对Pandas有了全面的了解。以下是核心要点回顾:

  1. 数据结构:掌握Series和DataFrame的创建和基本操作
  2. 文件读写:熟练导入和导出Excel、CSV、TXT等格式文件
  3. 数据操作:掌握列的增删改查、位置互换、重命名等操作
  4. 数据筛选:能够使用条件、逻辑运算、isin等方式筛选数据
  5. 数据排序:掌握按值排序、按索引排序、多列排序
  6. 数据分组:熟练使用groupby进行分组聚合操作
  7. 数据合并:掌握concat、merge、join等合并方式
  8. 类型转换:能够进行数据类型转换和时间类型处理
  9. 索引操作:掌握设置索引、重置索引、多层索引操作

学习建议

  • 📚 建议1:多加练习,动手实践是最好的学习方式。可以找一些公开数据集进行实践
  • 🎯 建议2:阅读Pandas官方文档,了解更多高级特性
  • 💡 建议3:参加数据分析相关项目,在实际项目中积累经验
  • 🔧 建议4:建立知识笔记,方便日后复习查阅
  • 🌟 建议5:结合NumPy、Matplotlib等库一起学习,形成完整的数据处理和可视化技能

练习题

  1. 创建一个包含10名学生信息的DataFrame(姓名、年龄、语文、数学、英语成绩),并进行以下操作:

    • 计算每个学生的总分和平均分
    • 筛选出总分前3名的学生
    • 按语文成绩降序排序
  2. 创建两个DataFrame,一个包含学生信息,一个包含课程成绩,使用merge进行关联操作

  3. 创建一个包含日期和销售数据的DataFrame,进行以下操作:

    • 提取年份、月份、季度信息
    • 按月份分组计算销售额总和
    • 按季度分组统计销售情况
  4. 创建一个包含空值的DataFrame,练习使用不同的空值处理方法(删除、填充)

  5. 创建一个多层索引的DataFrame,练习多层索引数据的访问和操作


📌 结束语:如果本文对你有帮助,欢迎转发给需要的朋友。有任何问题欢迎在评论区留言,我会第一时间回复!掌握Pandas是成为数据分析师的第一步,继续加油!

最新文章

随机文章

基本 文件 流程 错误 SQL 调试
  1. 请求信息 : 2026-07-03 02:19:23 HTTP/2.0 GET : https://f.mffb.com.cn/a/496029.html
  2. 运行时间 : 0.491137s [ 吞吐率:2.04req/s ] 内存消耗:4,978.55kb 文件加载:140
  3. 缓存信息 : 0 reads,0 writes
  4. 会话信息 : SESSION_ID=d521c891538fe322122b237c8438d44e
  1. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/public/index.php ( 0.79 KB )
  2. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/autoload.php ( 0.17 KB )
  3. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/composer/autoload_real.php ( 2.49 KB )
  4. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/composer/platform_check.php ( 0.90 KB )
  5. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/composer/ClassLoader.php ( 14.03 KB )
  6. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/composer/autoload_static.php ( 4.90 KB )
  7. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-helper/src/helper.php ( 8.34 KB )
  8. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-validate/src/helper.php ( 2.19 KB )
  9. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-orm/src/helper.php ( 1.47 KB )
  10. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-orm/stubs/load_stubs.php ( 0.16 KB )
  11. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/Exception.php ( 1.69 KB )
  12. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-container/src/Facade.php ( 2.71 KB )
  13. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/symfony/deprecation-contracts/function.php ( 0.99 KB )
  14. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/symfony/polyfill-mbstring/bootstrap.php ( 8.26 KB )
  15. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/symfony/polyfill-mbstring/bootstrap80.php ( 9.78 KB )
  16. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/symfony/var-dumper/Resources/functions/dump.php ( 1.49 KB )
  17. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-dumper/src/helper.php ( 0.18 KB )
  18. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/symfony/var-dumper/VarDumper.php ( 4.30 KB )
  19. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/App.php ( 15.30 KB )
  20. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-container/src/Container.php ( 15.76 KB )
  21. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/psr/container/src/ContainerInterface.php ( 1.02 KB )
  22. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/app/provider.php ( 0.19 KB )
  23. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/Http.php ( 6.04 KB )
  24. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-helper/src/helper/Str.php ( 7.29 KB )
  25. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/Env.php ( 4.68 KB )
  26. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/app/common.php ( 0.03 KB )
  27. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/helper.php ( 18.78 KB )
  28. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/Config.php ( 5.54 KB )
  29. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/config/app.php ( 0.95 KB )
  30. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/config/cache.php ( 0.78 KB )
  31. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/config/console.php ( 0.23 KB )
  32. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/config/cookie.php ( 0.56 KB )
  33. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/config/database.php ( 2.48 KB )
  34. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/facade/Env.php ( 1.67 KB )
  35. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/config/filesystem.php ( 0.61 KB )
  36. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/config/lang.php ( 0.91 KB )
  37. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/config/log.php ( 1.35 KB )
  38. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/config/middleware.php ( 0.19 KB )
  39. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/config/route.php ( 1.89 KB )
  40. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/config/session.php ( 0.57 KB )
  41. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/config/trace.php ( 0.34 KB )
  42. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/config/view.php ( 0.82 KB )
  43. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/app/event.php ( 0.25 KB )
  44. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/Event.php ( 7.67 KB )
  45. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/app/service.php ( 0.13 KB )
  46. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/app/AppService.php ( 0.26 KB )
  47. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/Service.php ( 1.64 KB )
  48. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/Lang.php ( 7.35 KB )
  49. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/lang/zh-cn.php ( 13.70 KB )
  50. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/initializer/Error.php ( 3.31 KB )
  51. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/initializer/RegisterService.php ( 1.33 KB )
  52. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/services.php ( 0.14 KB )
  53. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/service/PaginatorService.php ( 1.52 KB )
  54. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/service/ValidateService.php ( 0.99 KB )
  55. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/service/ModelService.php ( 2.04 KB )
  56. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-trace/src/Service.php ( 0.77 KB )
  57. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/Middleware.php ( 6.72 KB )
  58. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/initializer/BootService.php ( 0.77 KB )
  59. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-orm/src/Paginator.php ( 11.86 KB )
  60. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-validate/src/Validate.php ( 63.20 KB )
  61. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-orm/src/Model.php ( 23.55 KB )
  62. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-orm/src/model/concern/Attribute.php ( 21.05 KB )
  63. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-orm/src/model/concern/AutoWriteData.php ( 4.21 KB )
  64. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-orm/src/model/concern/Conversion.php ( 6.44 KB )
  65. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-orm/src/model/concern/DbConnect.php ( 5.16 KB )
  66. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-orm/src/model/concern/ModelEvent.php ( 2.33 KB )
  67. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-orm/src/model/concern/RelationShip.php ( 28.29 KB )
  68. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-helper/src/contract/Arrayable.php ( 0.09 KB )
  69. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-helper/src/contract/Jsonable.php ( 0.13 KB )
  70. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-orm/src/model/contract/Modelable.php ( 0.09 KB )
  71. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/Db.php ( 2.88 KB )
  72. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-orm/src/DbManager.php ( 8.52 KB )
  73. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/Log.php ( 6.28 KB )
  74. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/Manager.php ( 3.92 KB )
  75. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/psr/log/src/LoggerTrait.php ( 2.69 KB )
  76. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/psr/log/src/LoggerInterface.php ( 2.71 KB )
  77. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/Cache.php ( 4.92 KB )
  78. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/psr/simple-cache/src/CacheInterface.php ( 4.71 KB )
  79. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-helper/src/helper/Arr.php ( 16.63 KB )
  80. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/cache/driver/File.php ( 7.84 KB )
  81. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/cache/Driver.php ( 9.03 KB )
  82. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/contract/CacheHandlerInterface.php ( 1.99 KB )
  83. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/app/Request.php ( 0.09 KB )
  84. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/Request.php ( 55.78 KB )
  85. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/app/middleware.php ( 0.25 KB )
  86. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/Pipeline.php ( 2.61 KB )
  87. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-trace/src/TraceDebug.php ( 3.40 KB )
  88. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/middleware/SessionInit.php ( 1.94 KB )
  89. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/Session.php ( 1.80 KB )
  90. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/session/driver/File.php ( 6.27 KB )
  91. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/contract/SessionHandlerInterface.php ( 0.87 KB )
  92. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/session/Store.php ( 7.12 KB )
  93. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/Route.php ( 23.73 KB )
  94. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/route/RuleName.php ( 5.75 KB )
  95. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/route/Domain.php ( 2.53 KB )
  96. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/route/RuleGroup.php ( 22.43 KB )
  97. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/route/Rule.php ( 26.95 KB )
  98. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/route/RuleItem.php ( 9.78 KB )
  99. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/route/app.php ( 1.72 KB )
  100. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/facade/Route.php ( 4.70 KB )
  101. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/route/dispatch/Controller.php ( 4.74 KB )
  102. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/route/Dispatch.php ( 10.44 KB )
  103. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/app/controller/Index.php ( 4.81 KB )
  104. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/app/BaseController.php ( 2.05 KB )
  105. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-orm/src/facade/Db.php ( 0.93 KB )
  106. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-orm/src/db/connector/Mysql.php ( 5.44 KB )
  107. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-orm/src/db/PDOConnection.php ( 52.47 KB )
  108. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-orm/src/db/Connection.php ( 8.39 KB )
  109. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-orm/src/db/ConnectionInterface.php ( 4.57 KB )
  110. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-orm/src/db/builder/Mysql.php ( 16.58 KB )
  111. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-orm/src/db/Builder.php ( 24.06 KB )
  112. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-orm/src/db/BaseBuilder.php ( 27.50 KB )
  113. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-orm/src/db/Query.php ( 15.71 KB )
  114. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-orm/src/db/BaseQuery.php ( 45.13 KB )
  115. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-orm/src/db/concern/TimeFieldQuery.php ( 7.43 KB )
  116. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-orm/src/db/concern/AggregateQuery.php ( 3.26 KB )
  117. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-orm/src/db/concern/ModelRelationQuery.php ( 20.07 KB )
  118. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-orm/src/db/concern/ParamsBind.php ( 3.66 KB )
  119. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-orm/src/db/concern/ResultOperation.php ( 7.01 KB )
  120. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-orm/src/db/concern/WhereQuery.php ( 19.37 KB )
  121. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-orm/src/db/concern/JoinAndViewQuery.php ( 7.11 KB )
  122. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-orm/src/db/concern/TableFieldInfo.php ( 2.63 KB )
  123. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-orm/src/db/concern/Transaction.php ( 2.77 KB )
  124. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/log/driver/File.php ( 5.96 KB )
  125. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/contract/LogHandlerInterface.php ( 0.86 KB )
  126. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/log/Channel.php ( 3.89 KB )
  127. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/event/LogRecord.php ( 1.02 KB )
  128. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-helper/src/Collection.php ( 16.47 KB )
  129. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/facade/View.php ( 1.70 KB )
  130. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/View.php ( 4.39 KB )
  131. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/Response.php ( 8.81 KB )
  132. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/response/View.php ( 3.29 KB )
  133. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/Cookie.php ( 6.06 KB )
  134. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-view/src/Think.php ( 8.38 KB )
  135. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/contract/TemplateHandlerInterface.php ( 1.60 KB )
  136. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-template/src/Template.php ( 46.61 KB )
  137. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-template/src/template/driver/File.php ( 2.41 KB )
  138. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-template/src/template/contract/DriverInterface.php ( 0.86 KB )
  139. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/runtime/temp/067d451b9a0c665040f3f1bdd3293d68.php ( 11.98 KB )
  140. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-trace/src/Html.php ( 4.42 KB )
  1. CONNECT:[ UseTime:0.000932s ] mysql:host=127.0.0.1;port=3306;dbname=f_mffb;charset=utf8mb4
  2. SHOW FULL COLUMNS FROM `fenlei` [ RunTime:0.001476s ]
  3. SELECT * FROM `fenlei` WHERE `fid` = 0 [ RunTime:0.010087s ]
  4. SELECT * FROM `fenlei` WHERE `fid` = 63 [ RunTime:0.005303s ]
  5. SHOW FULL COLUMNS FROM `set` [ RunTime:0.001405s ]
  6. SELECT * FROM `set` [ RunTime:0.000745s ]
  7. SHOW FULL COLUMNS FROM `article` [ RunTime:0.001467s ]
  8. SELECT * FROM `article` WHERE `id` = 496029 LIMIT 1 [ RunTime:0.034357s ]
  9. UPDATE `article` SET `lasttime` = 1783016363 WHERE `id` = 496029 [ RunTime:0.014341s ]
  10. SELECT * FROM `fenlei` WHERE `id` = 66 LIMIT 1 [ RunTime:0.000796s ]
  11. SELECT * FROM `article` WHERE `id` < 496029 ORDER BY `id` DESC LIMIT 1 [ RunTime:0.033172s ]
  12. SELECT * FROM `article` WHERE `id` > 496029 ORDER BY `id` ASC LIMIT 1 [ RunTime:0.072181s ]
  13. SELECT * FROM `article` WHERE `id` < 496029 ORDER BY `id` DESC LIMIT 10 [ RunTime:0.053559s ]
  14. SELECT * FROM `article` WHERE `id` < 496029 ORDER BY `id` DESC LIMIT 10,10 [ RunTime:0.037506s ]
  15. SELECT * FROM `article` WHERE `id` < 496029 ORDER BY `id` DESC LIMIT 20,10 [ RunTime:0.017226s ]
0.492793s