当前位置:首页>python>Python入门课| 05. 数据结构

Python入门课| 05. 数据结构

  • 2026-06-30 18:42:49
Python入门课| 05. 数据结构

05. 数据结构

Python入门课》是作为生信小白入门重要的课程之一,学好python,是单细胞+空间转录组,Python全流程实战教学的基础。

B站同步播出:https://b23.tv/K9VXpXp

数据结构(理论)

数据结构(实操一)

数据结构(实操二)

数据结构(实操三)

数据结构(实操四)

Python入门课| 01. 绪论中,我们给大家介绍了python的特点用途,同时Python入门课| 02. python下载与安装手把手带领大家在不同系统中安装和下载Python;在Python入门课| 03. 变量与数据类型中的了解了变量与数据类型,主要是整数浮点数字符串布尔值;在Python入门课| 04. 类型转换中,python实现数据类型相互转换;接下来学习python中的数据结构,主要包括:列表与元组字典集合数组Series数据框DataFrameAnnData

图文内容

1. 数据结构

1.1 列表与元组

列表: 可修改的有序集合,使用方括号 [] 定义,适用于储存动态变化的数据

元组:不可修改的有序集合,使用 {} 定义,用于储存固定不变的信息

# 列表gene_list=['BRCA1','TP53','EGFR']print(gene_list)
['BRCA1', 'TP53', 'EGFR']
# 元组codon={'AUG','UAA','UAG'}print(codon)
{'AUG', 'UAG', 'UAA'}
gene_list.pop()
'EGFR'
gene_list
['BRCA1', 'TP53']
gene_list=['BRCA1','TP53','EGFR']list1=gene_list.pop(0)
list1
'BRCA1'
gene_list
['TP53', 'EGFR']
gene_list.append('SOX8')
gene_list
['TP53', 'EGFR', 'SOX8']

列表编辑方法:

方法
描述
示例
append(obj)
在列表末尾添加一个元素 obj
lst.append(10)
count(obj)
统计列表中某个元素 obj 出现的次数
lst.count(2)
extend(iterable)
在列表末尾一次性追加另一个可迭代对象中的所有元素
lst.extend([4, 5])
index(obj, start=0, end=len(lst))
返回元素 obj 第一次出现的索引,可指定范围
lst.index(3)
insert(index, obj)
在指定索引 index 位置插入元素 obj
lst.insert(1, 20)
pop(index=-1)
删除并返回指定索引的元素,默认删除最后一个
lst.pop()
remove(obj)
删除列表中第一个出现的元素 obj
lst.remove(2)
reverse()
原地反转列表(不返回新列表)
lst.reverse()
sort(key=None, reverse=False)
原地排序,可指定排序函数 key 和是否逆序
lst.sort(reverse=True)
# 元组编辑codon
{'AUG', 'UAA', 'UAG'}
codon.append('AUG')
---------------------------------------------------------------------------AttributeError                            Traceback (most recent call last) Cell In[27], line 1----> 1codon.append('AUG')AttributeError: 'set' object has no attribute 'append'
codon.pop(1)
---------------------------------------------------------------------------TypeError                                 Traceback (most recent call last) Cell In[28], line 1----> 1codon.pop(1)TypeError: set.pop() takes no arguments (1 given)

1.2 字典

  • 是 一种内置的数据结构,属于 容器类型(Container Type),用来存储 键-值(key-value)映射关系

  • 从使用角度来看,你在定义字典时,它会作为一个 变量 存在于内存里,但它的 数据类型(type) 是 dict

利用字典怎样方便地输出基因与表达信息

geneInfo = {'BRCA1'5.2            'TP53':3.8            'ALK':6.1}
type(geneInfo)
dict
geneInfo.items()
dict_items([('BRCA1', 5.2), ('TP53', 3.8), ('ALK', 6.1)])
geneInfo.keys()
dict_keys(['BRCA1', 'TP53', 'ALK'])
geneInfo.values()
dict_values([5.2, 3.8, 6.1])
gene_names=['BRCA1','TP53','ALK']gene_exp=[5.2,3.8,6.1]
expinfo = dict(zip(gene_names, gene_exp))print(expinfo)type(expinfo)
{'BRCA1': 5.2, 'TP53': 3.8, 'ALK': 6.1}
dict

Python 字典常用方法:

方法
作用
clear()
清空字典所有键值对
fromkeys(seq, value=None)
用序列 seq 创建新字典,所有键的值都是 value
get(key, default=None)
获取键的值,不存在时返回 default(不会报错)
items()
返回字典的 (键, 值) 视图对象,可迭代
keys()
返回所有键的视图对象
pop(key[, default])
删除并返回指定键的值,若键不存在返回 default
setdefault(key, default=None)
获取键的值,若不存在则插入该键并赋值为 default
update([other])
用另一个字典或可迭代对象更新当前字典
values()
返回所有值的视图对象
copy()
浅拷贝当前字典

利用字典怎样快速方便地更新基因表达信息

geneInfo={'BRCA1':5.2,'TP53':3.8,'ALK':6.1}geneInfo_new={'TP53':4.6,'MAPK1':7.5,'CLINK':2.1}geneInfo.update(geneInfo_new)geneInfo
{'BRCA1': 5.2, 'TP53': 4.6, 'ALK': 6.1, 'MAPK1': 7.5, 'CLINK': 2.1}

假设基因表达信息有部分基因重复出现,如何快速解决这个问题?

names=['BRCA1','BRCA2','BRCA3','BRCA1']

1.3 集合

是Python中的一种 无序、元素唯一的可变数据结构,用于快速去重和集合运算

namesSet=set(names)namesSet
{'BRCA1', 'BRCA2', 'BRCA3'}
aSet=set('hello')print(aSet)
{'e', 'h', 'l', 'o'}
fSet=frozenset('hello')print(fSet)
frozenset({'e', 'h', 'l', 'o'})
数学符号
Python 符号
in
=
==
!=
<
<=
>
>=
&
|
- 或 \
-
Δ
^
aSet=set('sunrise')bSet=set('sunset')
aSet & bSet
{'e', 'n', 's', 'u'}
aSet | bSet
{'e', 'i', 'n', 'r', 's', 't', 'u'}
aSet - bSet
{'i', 'r'}
aSet -= set('sun')aSet
{'e', 'i', 'r'}
aSet.add('!')aSet
{'!', 'e', 'i', 'r'}
aSet.remove('!')aSet
{'e', 'i', 'r'}
aSet.update('Yeah')aSet
{'Y', 'a', 'e', 'h', 'i', 'r'}
aSet.clear()aSet
set()

1.4 数组

NumPy 数组(numpy.ndarray):

  • 使用最广泛的科学计算数组

  • 特点:多维数组、高效、支持向量化操作

array的创建

import numpy as npaArray = np.array([1,2,3])aArray
array([1, 2, 3])
bArray = np.array([(1,2,3),(4,5,6),(7,8,9)])bArray
array([[1, 2, 3],
        [4, 5, 6],
        [7, 8, 9]])

(1) array函数

函数
示例
arange(start, stop, step)np.arange(0,5,1)
 → [0 1 2 3 4]
linspace(start, stop, num)np.linspace(0,1,5)
 → [0. 0.25 0.5 0.75 1.]
array(object)np.array([1,2,3])
 → [1 2 3]
zeros(shape)np.zeros((2,3))
 → [[0 0 0],[0 0 0]]
zeros_like(a)np.zeros_like(np.array([1,2]))
 → [0 0]
eye(N)np.eye(3)
 → [[1 0 0],[0 1 0],[0 0 1]]
identity(n)np.identity(3)
 → [[1 0 0],[0 1 0],[0 0 1]]
fromfile(filename)np.fromfile('data.bin', dtype=int)
fromfunction(function, shape)np.fromfunction(lambda i,j: i+j, (3,3))
 → [[0 1 2],[1 2 3],[2 3 4]]
copy(a)b = np.copy(a)
np.arange()
---------------------------------------------------------------------------TypeError                                 Traceback (most recent call last) Cell In[55], line 1----> 1np.arange()TypeError: arange() requires stop to be specified.
np.arange(0,5,1)
array([0, 1, 2, 3, 4])
np.linspace(0,1,5)
array([0.  , 0.25, 0.5 , 0.75, 1.  ])
np.array([1,2,3])
array([1, 2, 3])
np.zeros((2,3))
array([[0., 0., 0.],
        [0., 0., 0.]])
np.zeros_like(np.array([1,2]))
array([0, 0])
np.ones((4))
array([1., 1., 1., 1.])
np.eye(2,4,0)
array([[1., 0., 0., 0.], 
       [0., 1., 0., 0.]])
np.identity(3)
array([[1., 0., 0.], 
        [0., 1., 0.],
        [0., 0., 1.]])
np.random.rand(5)
array([0.63772951, 0.81217848, 0.20310379, 0.92996627, 0.087836  ])
np.random.rand(5,5)
array([[0.6905823 , 0.25951312, 0.88697466, 0.71435988, 0.39357782],
        [0.82124649, 0.95459649, 0.83051724, 0.94359563, 0.63488875],
        [0.45909436, 0.74779059, 0.35560115, 0.28928883, 0.98640251],
        [0.80774419, 0.99356694, 0.65280914, 0.12160228, 0.03459244],
        [0.10477458, 0.20987793, 0.6466776 , 0.41415308, 0.38370915]])
np.random.randn(2)
array([-1.0325992 , -1.13576414])
arr = np.random.randint(1,100,10)arr
array([56, 94,  9, 54, 81, 65, 48, 88, 12, 14])
arr.reshape(2,5)
array([[56, 94,  9, 54, 81],
        [65, 48, 88, 12, 14]])
arr.max()
np.int64(94)
arr.argmax()
np.int64(1)

(2) array索引和选择

arr_2d = np.array([[5,10,15],[20,25,30],[35,40,45]])
arr_2d
array([[ 5, 10, 15],
        [20, 25, 30],
        [35, 40, 45]])
arr_2d[0]
array([ 5, 10, 15])
arr_2d[1][1]
np.int64(25)
arr_2d[:2,1:]
array([[10, 15],
        [25, 30]])

(3) array间的计算

aArray = np.array([(5,5,5),(5,5,5)])bArray = np.array([(2,2,2),(2,2,2)])
cArray = aArray * bArraycArray
array([[10, 10, 10],
        [10, 10, 10]])
aArray += bArrayprint(aArray)
[[7 7 7]
  [7 7 7]]
arr = np.arange(1,11)arr
array([ 1,  2,  3,  4,  5,  6,  7,  8,  9, 10])
bool_arr = arr > 5bool_arr
array([False, False, False, False, False,  True,  True,  True,  True,
         True])
arr[bool_arr]
array([ 6,  7,  8,  9, 10])
arr / arr
array([1., 1., 1., 1., 1., 1., 1., 1., 1., 1.])
xarr = np.arange(0,10)xarr
array([0, 1, 2, 3, 4, 5, 6, 7, 8, 9])
0 / 0
---------------------------------------------------------------------------ZeroDivisionError                         Traceback (most recent call last) Cell In[84], line 1----> 10/0ZeroDivisionError: division by zero
xarr / xarr
/tmp/ipykernel_33593/727807742.py:1: RuntimeWarning: invalid value encountered in divide   xarr / xarr
array([nan,  1.,  1.,  1.,  1.,  1.,  1.,  1.,  1.,  1.])
1 / xarr
/tmp/ipykernel_33593/3789554754.py:1: RuntimeWarning: divide by zero encountered in divide   1 / xarr
array([       inf, 1.        , 0.5       , 0.33333333, 0.25      ,        0.2       , 0.16666667, 0.14285714, 0.125     , 0.11111111])
np.max(arr)
np.int64(10)
np.min(arr)
np.int64(1)
np.sqrt(arr)
array([1.        , 1.41421356, 1.73205081, 2.        , 2.23606798,        2.44948974, 2.64575131, 2.82842712, 3.        , 3.16227766])
np.exp(arr)
array([2.71828183e+00, 7.38905610e+00, 2.00855369e+01, 5.45981500e+01,
        1.48413159e+02, 4.03428793e+02, 1.09663316e+03, 2.98095799e+03,
        8.10308393e+03, 2.20264658e+04])
Test:怎么利用array生成九九乘法表? fromfunction(): - 索引生成法 - 每个元素的值由它在数组中的 坐标 决定 - 常用来生成规律性矩阵(乘法表、网格函数等)
def fun(x,y):    return (x+1)*(y+1)xArray = np.fromfunction(fun,(9,9))print(xArray)
[[ 1.  2.  3.  4.  5.  6.  7.  8.  9.]
  [ 2.  4.  6.  8. 10. 12. 14. 16. 18.]
  [ 3.  6.  9. 12. 15. 18. 21. 24. 27.]
  [ 4.  8. 12. 16. 20. 24. 28. 32. 36.]
  [ 5. 10. 15. 20. 25. 30. 35. 40. 45.]
  [ 6. 12. 18. 24. 30. 36. 42. 48. 54.]
  [ 7. 14. 21. 28. 35. 42. 49. 56. 63.]
  [ 8. 16. 24. 32. 40. 48. 56. 64. 72.]
  [ 9. 18. 27. 36. 45. 54. 63. 72. 81.]]

1.5 Series

一种 一维带标签的数组。它既类似于 数组/列表,又类似于 字典

  • 一维数据结构:存储整数、浮点数、字符串等
  • 带索引(index):每个元素都有标签
  • 可以通过索引访问:支持数字索引或自定义标签
import pandas as pd# 从列表创建 Seriess1 = pd.Series([10203040])print(s1)
0    10 
1    20 
2    30 
3    40 
dtype: int64

访问 Series 数据

# 按位置访问print(s1[0])  # 输出 10# 统计操作print(s1.sum())   # 输出 100print(s1.mean())  # 输出 25.0
10 
100
25.0
如果你希望自定义索引:
s2 = pd.Series([10203040], index=['a','b','c','d'])print(s2)
a    10 
b    20 
c    30 
d    40 
dtype: int64
Series 就是 带标签的一维数组,可以理解为 带索引的列表或简单的字典

1.6 数据框 DataFrame

是二维表格数据结构,可以看作是由多列 Series 组成的表格,每列可以有不同的数据类型,大致可看成共享同一个index的Series集合

(1) DataFrame的基本结构

  • 二维(行 × 列)

  • 每列是一个 Series

  • 行列都有索引

  • 支持各种操作:筛选、排序、统计、合并等

import pandas as pdimport numpy as np
# 从字典创建 DataFramedf = pd.DataFrame({    "Name": ["Alice""Bob""Charlie"],    "Age": [25, 30, 35],    "Score": [85.5, 90.0, 88.0]})print(df)
      Name  Age  Score
0    Alice   25   85.5 
1      Bob   30   90.0 
2  Charlie   35   88.0
  • 默认行索引是 0,1,2

  • 每列可以是不同类型(字符串、整数、浮点数等)

(2) 访问数据

# 获取一列(返回 Series)print(df["Name"])
0      Alice 
1        Bob 
2    Charlie 
Name: Name, dtype: object
# 获取多列(返回 DataFrame)print(df[["Name""Score"]])
      Name  Score 
0    Alice   85.5 
1      Bob   90.0 
2  Charlie   88.0
# 按行索引获取print(df.iloc[1])  # 第二行
Name      Bob 
Age        30 
Score    90.0 
Name: 1, dtype: object
# 按条件筛选print(df[df["Score"] > 89])
  Name  Age  Score 
1  Bob   30   90.0

(3) 数据处理实战

import pandas as pdimport numpy as np# 基因名genes = ["GeneA""GeneB""GeneC""GeneD""GeneE"]# 样本名samples = ["Sample1""Sample2""Sample3""Sample4"]# 随机生成 5 个基因在 4 个样本中的表达量(整数模拟 TPM/Counts)np.random.seed(1212)  # 固定随机种子,结果可复现data = np.random.randint(50200, size=(len(genes), len(samples)))# 构造 DataFramedf = pd.DataFrame(data, index=genes, columns=samples)print(df)
       Sample1  Sample2  Sample3  Sample4 
GeneA      186      116      151      191 
GeneB      155       83       77       89 
GeneC       55      192       67      134 
GeneD      198       69      157      168 
GeneE      129      122      132      173
# 显示形状df.shape
(5, 4)
# 显示索引df.index
Index(['GeneA', 'GeneB', 'GeneC', 'GeneD', 'GeneE'], dtype='object')
# 显示列名df.columns
Index(['Sample1', 'Sample2', 'Sample3', 'Sample4'], dtype='object')
# 显示数据的值df.values
array([[186, 116, 151, 191],
        [155,  83,  77,  89],
        [ 55, 192,  67, 134],
        [198,  69, 157, 168],
        [129, 122, 132, 173]])
# 数据描述df.describe()
Sample1
Sample2
Sample3
Sample4
count
5.000000
5.000000
5.000000
5.00000
mean
144.600000
116.400000
116.800000
151.00000
std
56.888487
47.721065
42.073745
40.32989
min
55.000000
69.000000
67.000000
89.00000
25%
129.000000
83.000000
77.000000
134.00000
50%
155.000000
116.000000
132.000000
168.00000
75%
186.000000
122.000000
151.000000
173.00000
max
198.000000
192.000000
157.000000
191.00000
# 数据查看df.head(2)
Sample1
Sample2
Sample3
Sample4
GeneA
186
116
151
191
GeneB
155
83
77
89
df.tail(4)
Sample1
Sample2
Sample3
Sample4
GeneB
155
83
77
89
GeneC
55
192
67
134
GeneD
198
69
157
168
GeneE
129
122
132
173
# 数据选择df[u'GeneA':u'GeneE']
Sample1
Sample2
Sample3
Sample4
GeneA
186
116
151
191
GeneB
155
83
77
89
GeneC
55
192
67
134
GeneD
198
69
157
168
GeneE
129
122
132
173
df['Sample2']
GeneA    116 
GeneB     83 
GeneC    192 
GeneD     69 
GeneE    122 Name: Sample2, dtype: int64
df.Sample2
GeneA    116 
GeneB     83 
GeneC    192 
GeneD     69 
GeneE    122 Name: Sample2, dtype: int64
df.iloc[0:6,]
Sample1
Sample2
Sample3
Sample4
GeneA
186
116
151
191
GeneB
155
83
77
89
GeneC
55
192
67
134
GeneD
198
69
157
168
GeneE
129
122
132
173
df.loc['GeneA':'GeneE',]
Sample1
Sample2
Sample3
Sample4
GeneA
186
116
151
191
GeneB
155
83
77
89
GeneC
55
192
67
134
GeneD
198
69
157
168
GeneE
129
122
132
173
df.loc[:,['Sample1','Sample3']]
Sample1
Sample3
GeneA
186
151
GeneB
155
77
GeneC
55
67
GeneD
198
157
GeneE
129
132
df.iloc[:1,2]
GeneA    151 
Name: Sample3, dtype: int64
df[df>150]bool_df=df>150df
Sample1
Sample2
Sample3
Sample4
GeneA
186
116
151
191
GeneB
155
83
77
89
GeneC
55
192
67
134
GeneD
198
69
157
168
GeneE
129
122
132
173
bool_df
Sample1
Sample2
Sample3
Sample4
GeneA
True
False
True
True
GeneB
True
False
False
False
GeneC
False
True
False
False
GeneD
True
False
True
True
GeneE
False
False
False
True
df[bool_df]
Sample1
Sample2
Sample3
Sample4
GeneA
186.0
NaN
151.0
191.0
GeneB
155.0
NaN
NaN
NaN
GeneC
NaN
192.0
NaN
NaN
GeneD
198.0
NaN
157.0
168.0
GeneE
NaN
NaN
NaN
173.0
df[df>150]
Sample1
Sample2
Sample3
Sample4
GeneA
186.0
NaN
151.0
191.0
GeneB
155.0
NaN
NaN
NaN
GeneC
NaN
192.0
NaN
NaN
GeneD
198.0
NaN
157.0
168.0
GeneE
NaN
NaN
NaN
173.0
df[df['Sample1']>150][['Sample2','Sample3']]
Sample2
Sample3
GeneA
116
151
GeneB
83
77
GeneD
69
157
df['Sample1']>150
GeneA     True 
GeneB     True 
GeneC    False 
GeneD     True 
GeneE    False Name: Sample1, dtype: bool
df[df['Sample1']>150]
Sample1
Sample2
Sample3
Sample4
GeneA
186
116
151
191
GeneB
155
83
77
89
GeneD
198
69
157
168
df[df['Sample1']>150][['Sample2','Sample3']]
Sample2
Sample3
GeneA
116
151
GeneB
83
77
GeneD
69
157
boolsers=df['Sample1']>150result = df[boolsers]my_cols = ['Sample2','Sample3']result[my_cols]
Sample2
Sample3
GeneA
116
151
GeneB
83
77
GeneD
69
157
df
Sample1
Sample2
Sample3
Sample4
GeneA
186
116
151
191
GeneB
155
83
77
89
GeneC
55
192
67
134
GeneD
198
69
157
168
GeneE
129
122
132
173
df[(df['Sample1']>150)|(df['Sample2']<150)]
Sample1
Sample2
Sample3
Sample4
GeneA
186
116
151
191
GeneB
155
83
77
89
GeneD
198
69
157
168
GeneE
129
122
132
173
df.reset_index()
index
Sample1
Sample2
Sample3
Sample4
0
GeneA
186
116
151
191
1
GeneB
155
83
77
89
2
GeneC
55
192
67
134
3
GeneD
198
69
157
168
4
GeneE
129
122
132
173
newind = 'sa y my na mes'.split()newind
['sa', 'y', 'my', 'na', 'mes']
df['word'] = newinddf
Sample1
Sample2
Sample3
Sample4
word
GeneA
186
116
151
191
sa
GeneB
155
83
77
89
y
GeneC
55
192
67
134
my
GeneD
198
69
157
168
na
GeneE
129
122
132
173
mes
df.set_index('word')
Sample1
Sample2
Sample3
Sample4
word
sa
186
116
151
191
y
155
83
77
89
my
55
192
67
134
na
198
69
157
168
mes
129
122
132
173
data = np.random.randn(6,2)data
array([[-0.19228917,  0.1381977 ],
        [-0.79620222, -1.47975643],
        [ 0.00552813, -1.16490799],
        [-0.48173024, -1.64570701],
        [-0.02612605,  0.49249298],
        [-0.65343868, -0.69494063]])
outside = ['G1','G1','G1','G2','G2','G2']inside = [1,2,3,1,2,3]
list(zip(outside,inside))
[('G1', 1), ('G1', 2), ('G1', 3), ('G2', 1), ('G2', 2), ('G2', 3)]
# 多层次索引 index levelsoutside = ['G1','G1','G1','G2','G2','G2']inside = [1,2,3,1,2,3]hier_index = list(zip(outside,inside))hier_index = pd.MultiIndex.from_tuples(hier_index)
df = pd.DataFrame(data,index=hier_index,columns=['A','B'])df
A
B
G1
1
-0.192289
0.138198
2
-0.796202
-1.479756
3
0.005528
-1.164908
G2
1
-0.481730
-1.645707
2
-0.026126
0.492493
3
-0.653439
-0.694941
df.loc['G1'].loc[2]
A   -0.796202 
B   -1.479756 
Name: 2, dtype: float64
df.index.names=['Group','Sample']df
A
B
Group
Sample
G1
1
-0.192289
0.138198
2
-0.796202
-1.479756
3
0.005528
-1.164908
G2
1
-0.481730
-1.645707
2
-0.026126
0.492493
3
-0.653439
-0.694941
df.loc['G1'].loc[2]['A']
-0.7962022239827933
df.xs('G1',level='Group')
A
B
Sample
1
-0.192289
0.138198
2
-0.796202
-1.479756
3
0.005528
-1.164908

再进行一些综合实际的运算测试

import pandas as pdimport numpy as np# 构造一个简单的基因表达矩阵data = {  "Gene": ["GeneA","GeneB","GeneC","GeneD","GeneE","GeneF"],  "Sample1": [10,50,30,80,5,60],  "Sample2": [20,45,25,70,8,55],  "Sample3": [15,55,28,90,3,65],  "CellType": ["T","B","T","B","NK","T"] } df = pd.DataFrame(data) print(df)
    Gene  Sample1  Sample2  Sample3 CellType 
0  GeneA       10       20       15        T 
1  GeneB       50       45       55        B 
2  GeneC       30       25       28        T 
3  GeneD       80       70       90        B 
4  GeneE        5        8        3       NK 
5  GeneF       60       55       65        T

简单统计与筛选

df.describe()
Sample1
Sample2
Sample3
count
6.000000
6.000000
6.000000
mean
39.166667
37.166667
42.666667
std
29.396712
23.455632
33.001010
min
5.000000
8.000000
3.000000
25%
15.000000
21.250000
18.250000
50%
40.000000
35.000000
41.500000
75%
57.500000
52.500000
62.500000
max
80.000000
70.000000
90.000000
# 筛选:找出表达量 > 50 的基因df[df["Sample1"] > 50]
Gene
Sample1
Sample2
Sample3
CellType
3
GeneD
80
70
90
B
5
GeneF
60
55
65
T
df
Gene
Sample1
Sample2
Sample3
CellType
0
GeneA
10
20
15
T
1
GeneB
50
45
55
B
2
GeneC
30
25
28
T
3
GeneD
80
70
90
B
4
GeneE
5
8
3
NK
5
GeneF
60
55
65
T
# 排序:按 Sample3 表达量排序(ascending升序)df.sort_values(by="Sample3",ascending=False)
Gene
Sample1
Sample2
Sample3
CellType
3
GeneD
80
70
90
B
5
GeneF
60
55
65
T
1
GeneB
50
45
55
B
2
GeneC
30
25
28
T
0
GeneA
10
20
15
T
4
GeneE
5
8
3
NK
# 计数统计:各细胞类型基因数目df["CellType"].value_counts()
CellType 
T     3 
B     2 
NK    1 
Name: count, dtype: int64
df.groupby("CellType")[["Sample1","Sample2","Sample3"]]
<pandas.core.groupby.generic.DataFrameGroupBy object at 0x7fdb1040ffa0>
# 分组:按 CellType 计算平均表达量df.groupby("CellType")[["Sample1","Sample2","Sample3"]].mean()
Sample1
Sample2
Sample3
CellType
B
65.000000
57.500000
72.5
NK
5.000000
8.000000
3.0
T
33.333333
33.333333
36.0
new_row = pd.DataFrame({"Gene":['GeneG'],"Sample1": [40], "Sample2": [35], "Sample3": [50], "CellType": ["NK"]}, index=["6"])print(new_row)
    Gene  Sample1  Sample2  Sample3 CellType 
6  GeneG       40       35       50       NK
# 如果新测了一个基因GeneG,可以追加进去new_row = pd.DataFrame({"Gene":['GeneG'],"Sample1": [40], "Sample2": [35], "Sample3": [50], "CellType": ["NK"]}, index=["6"])df_concat = pd.concat([df, new_row])print(df_concat)
    Gene  Sample1  Sample2  Sample3 CellType 
0  GeneA       10       20       15        T 
1  GeneB       50       45       55        B 
2  GeneC       30       25       28        T 
3  GeneD       80       70       90        B 
4  GeneE        5        8        3       NK 
5  GeneF       60       55       65        T 
6  GeneG       40       35       50       NK
# join(像 SQL 合并)print(df)df_info = pd.DataFrame({    "Gene": ["GeneA""GeneB""GeneC""GeneD""GeneF"],    "Description": ["Signal""Receptor""Kinase""TF""Enzyme"]}).set_index("Gene")df_join = df.join(df_info, on = "Gene", how="left"# 对左表进行链接    print(df_join)
    Gene  Sample1  Sample2  Sample3 CellType 
0  GeneA       10       20       15        T 
1  GeneB       50       45       55        B 
2  GeneC       30       25       28        T 
3  GeneD       80       70       90        B 
4  GeneE        5        8        3       NK 
5  GeneF       60       55       65        T
     Gene  Sample1  Sample2  Sample3 CellType Description 
0  GeneA       10       20       15        T      Signal 
1  GeneB       50       45       55        B    Receptor 
2  GeneC       30       25       28        T      Kinase 
3  GeneD       80       70       90        B          TF 
4  GeneE        5        8        3       NK         NaN 
5  GeneF       60       55       65        T      Enzyme
df_info = pd.DataFrame({    "Gene": ["GeneA""GeneB""GeneC""GeneD","GeneE","GeneF"],    "Description": ["Signal""Receptor""Kinase","Gene","TF""Enzyme"]}).set_index("Gene")print(df_info)
      Description 
Gene              
GeneA      Signal 
GeneB    Receptor 
GeneC      Kinase 
GeneD        Gene 
GeneE          TF 
GeneF      Enzyme
df_join = df.join(df_info, on = "Gene", how="left")df_join
Gene
Sample1
Sample2
Sample3
CellType
Description
0
GeneA
10
20
15
T
Signal
1
GeneB
50
45
55
B
Receptor
2
GeneC
30
25
28
T
Kinase
3
GeneD
80
70
90
B
Gene
4
GeneE
5
8
3
NK
TF
5
GeneF
60
55
65
T
Enzyme
# 合并:把基因注释表 merge 进来gene_info = pd.DataFrame({    "Gene": ["GeneA","GeneB","GeneC","GeneD","GeneE","GeneF"],    "Pathway": ["Path1","Path1","Path2","Path2","Path3","Path1"]})df_merge = pd.merge(df, gene_info, on="Gene")print(df_merge)
    Gene  Sample1  Sample2  Sample3 CellType Pathway 
0  GeneA       10       20       15        T   Path1 
1  GeneB       50       45       55        B   Path1 
2  GeneC       30       25       28        T   Path2 
3  GeneD       80       70       90        B   Path2 
4  GeneE        5        8        3       NK   Path3 
5  GeneF       60       55       65        T   Path1
gene_info = pd.DataFrame({    "Gene": ["GeneA","GeneB","GeneC","GeneD","GeneE","GeneF"],    "Pathway": ["Path1","Path1","Path2","Path2","Path3","Path1"]})print(gene_info)
    Gene Pathway 
0  GeneA   Path1 
1  GeneB   Path1 
2  GeneC   Path2 
3  GeneD   Path2 
4  GeneE   Path3 
5  GeneF   Path1

1.7 Anndata

(Annotated data)

单细胞/空间分析中最常用的数据结构,尤其是在 Scanpy / scvelo / Squidpy 里,用来存储单细胞或空间转录组数据。它本质上是 带行列注释的二维矩阵,可以存储表达矩阵、元数据、降维结果等

特点

  • X:主表达矩阵(细胞 × 基因)

  • obs:行注释(每个细胞的元信息,如 cell type、nUMI)

  • var:列注释(每个基因的信息,如基因名、类型)

  • obsm:行的多维注释(如 PCA、UMAP 坐标)

  • varm:列的多维注释

  • layers:不同版本的表达矩阵(如原始 counts、归一化后的表达)

创建示例

import anndataimport pandas as pdimport numpy as np
# 构建表达矩阵 5 个细胞 × 3 个基因X = np.random.rand(5,3)X
array([[0.19465879, 0.75363168, 0.67011092],
        [0.6730949 , 0.1981402 , 0.5818332 ],
        [0.19600538, 0.90684518, 0.77806403],
        [0.93672809, 0.19048208, 0.63820134],
        [0.03492986, 0.69859281, 0.49401032]])
# 行注释:细胞信息obs = pd.DataFrame({    "cell_type": ["A","A","B","B","C"],    "nUMI": [1000120090011001050]}, index=[f"cell{i}" for i in range(5)])
obs
cell_type
nUMI
cell0
A
1000
cell1
A
1200
cell2
B
900
cell3
B
1100
cell4
C
1050
# 列注释:基因信息var = pd.DataFrame({    "gene_name": ["Gene1""Gene2""Gene3"]}, index=["Gene1","Gene2","Gene3"])var
gene_name
Gene1
Gene1
Gene2
Gene2
Gene3
Gene3
# 创建 AnnData 对象adata = anndata.AnnData(X=X,obs=obs,var=var)print(adata)
AnnData object with n_obs × n_vars = 5 × 3
     obs: 'cell_type', 'nUMI'
     var: 'gene_name'
# 访问表达矩阵print(adata.X)
[[0.19465879 0.75363168 0.67011092]
  [0.6730949  0.1981402  0.5818332 ]
  [0.19600538 0.90684518 0.77806403]
  [0.93672809 0.19048208 0.63820134]
  [0.03492986 0.69859281 0.49401032]]
# 访问行注释print(adata.obs)
      cell_type  nUMI 
cell0         A  1000 
cell1         A  1200 
cell2         B   900 
cell3         B  1100 
cell4         C  1050
# 访问列注释print(adata.var)
      gene_name 
Gene1     Gene1 
Gene2     Gene2 
Gene3     Gene3
# 添加降维坐标adata.obsm["X_umap"] = np.random.rand(5,2)
adata.obsm["X_umap"]
array([[0.65570112, 0.95325181],
        [0.92487895, 0.28615184],
        [0.84072823, 0.18507465],
        [0.88428376, 0.67256536],
        [0.62252519, 0.11358681]])
  • AnnData 是 带注释的二维矩阵

  • 非常适合单细胞、空间转录组数据

  • 支持存储多种层(counts、归一化表达、降维、TCR/BCR 信息等)

Python入门课

1、课程简介

生信基地希望能够给大家提供系统性形成性规范性的生信教学。本次《Python入门课》可针对性的指导答疑,分为"Python课程绪论"、"Python下载与安装"、"变量与数据变型"、"类型转换"、"数据结构"、"运算符和表达式"、"语法与语句"、"数据的读取与保存"、"模块与包"、"基于Matplotlib的基础可视化"、"简单机器学习入门"十一个模块共21节课。当然,我们也不做生信快餐,课程视频剪辑完毕,永久回放。后续我们会持续拉群在群里进行课程内容答疑

2、Python介绍

Python作为本次课程核心编程语言,语法简洁、库生态丰富、计算高效,是数据科学与自动化开发的主流选择,兼顾入门友好与高效开发。随着研究数据量,Python可弥补R语言在处理规模与扩展性上的不足,更好适合现科研需求。

我们制作的单细胞空间转录组教程几乎也全是基于Python环境。很多同学找我们学习单细胞的时候都表示不想学习编程语言,直接学习单细胞/空间转录组分析,不积跬步无以至千里,这显然是不现实的,所以,欢迎大家来参加此次的课程。

报名/缴费二维码:

资料&课表

本次课程的学习资料可以联系文末客服微信领取:

课程目录:

1. Python课程绪论

2. Python下载与安装

2.1 官网下载

2.2 安装(以 Windows 为例)

2.3 Linux / macOS 安装

2.4 Miniconda 安装 python(虚拟环境)

3. 变量与数据类型

3.1 整数

3.2 浮点数

3.3 字符串

3.4 布尔值

4. 类型转换

5. 数据结构

5.1 列表与元组

5.2 字典

5.3 集合

5.4 数组

5.5 Series

5.6 数据框 DataFrame

5.7 Anndata

6. 运算符和表达式

6.1 算数运算符

6.2 比较运算符

6.3 逻辑运算符

6.4 位运算符

6.5 赋值运算符

7. 语法与语句

7.1 if条件语句

7.2 for循环语句

7.3 while循环语句

7.4 跳转语句

7.5 函数定义与调用

8. 数据的读取与保存

8.1 基础信息

8.2 不同格式文件读取

9. 模块与包

10. 基于Matplotlib的基础可视化

10.1 基础可视化

10.2 图像大小和 DPI 设置

10.3 设置图例

10.4 实战练习

11. 简单机器学习入门

如何联系我们

留一个领取资料开箱即用的单细胞分析镜像微信号[Biomamba_zhushou],方便各位随时交流。同时我们也构建了交流群矩阵欢迎大家入群讨论。
大家可以阅读完这几篇之后添加
给生信入门初学者的小贴士
没有检索,就没有发言权

已有生信基地联系方式的同学无需重复添加

您点的每个赞和在看,我都认真当成了喜欢

最新文章

随机文章

基本 文件 流程 错误 SQL 调试
  1. 请求信息 : 2026-07-03 18:10:34 HTTP/2.0 GET : https://f.mffb.com.cn/a/493607.html
  2. 运行时间 : 0.219146s [ 吞吐率:4.56req/s ] 内存消耗:4,758.65kb 文件加载:140
  3. 缓存信息 : 0 reads,0 writes
  4. 会话信息 : SESSION_ID=f1db0eba773928a3d7ed7ba04c727c37
  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.000439s ] mysql:host=127.0.0.1;port=3306;dbname=f_mffb;charset=utf8mb4
  2. SHOW FULL COLUMNS FROM `fenlei` [ RunTime:0.000647s ]
  3. SELECT * FROM `fenlei` WHERE `fid` = 0 [ RunTime:0.005646s ]
  4. SELECT * FROM `fenlei` WHERE `fid` = 63 [ RunTime:0.004345s ]
  5. SHOW FULL COLUMNS FROM `set` [ RunTime:0.000588s ]
  6. SELECT * FROM `set` [ RunTime:0.006640s ]
  7. SHOW FULL COLUMNS FROM `article` [ RunTime:0.000783s ]
  8. SELECT * FROM `article` WHERE `id` = 493607 LIMIT 1 [ RunTime:0.009031s ]
  9. UPDATE `article` SET `lasttime` = 1783073434 WHERE `id` = 493607 [ RunTime:0.014472s ]
  10. SELECT * FROM `fenlei` WHERE `id` = 66 LIMIT 1 [ RunTime:0.000315s ]
  11. SELECT * FROM `article` WHERE `id` < 493607 ORDER BY `id` DESC LIMIT 1 [ RunTime:0.014310s ]
  12. SELECT * FROM `article` WHERE `id` > 493607 ORDER BY `id` ASC LIMIT 1 [ RunTime:0.002488s ]
  13. SELECT * FROM `article` WHERE `id` < 493607 ORDER BY `id` DESC LIMIT 10 [ RunTime:0.031501s ]
  14. SELECT * FROM `article` WHERE `id` < 493607 ORDER BY `id` DESC LIMIT 10,10 [ RunTime:0.030737s ]
  15. SELECT * FROM `article` WHERE `id` < 493607 ORDER BY `id` DESC LIMIT 20,10 [ RunTime:0.013489s ]
0.220783s