读取h5ad文件

python 复制代码
import scanpy as sc

annData = sc.read_h5ad("D:/xzj-2023/c0.h5ad")

var_df=pd.DataFrame(annData.var)

var_df.to_csv('D:/c0_var.csv', index=False, sep='\t')

obs_df=pd.DataFrame(annData.obs)

obs_df.to_csv('D:/c0_obs.csv', index=False, sep='\t')

X_df=pd.DataFrame(annData.X)

X_df.to_csv('D:/c0_X.csv', index=False, sep='\t')

#读取细胞类型
print(adata.obs['cell_type'])
#Name: cell_type, Length: 11851, dtype: category
# Categories (7, object): ['fibroblast', 'T cell', 'endothelial cell', 'hepatocyte', 'macrophage',
   #                      'monocyte', 'malignant cell']

图片来源https://www.jianshu.com/p/18006139bbed

相关推荐
Yu_Lijing7 小时前
Python数据分析和数据处理库Pandas(Series篇)
人工智能·python·数据分析·pandas
AI效率工坊7 小时前
【Python实战】10万行数据自动清洗:pandas+AI智能识别+异常检测完整方案
人工智能·python·pandas
人工干智能9 小时前
科普:pandas 中的类 SQL语句:transaction.groupby(“card_id“)[‘purchase_day‘].diff()
数据库·sql·pandas
神秘剑客_CN10 小时前
python安装requests及pandas
开发语言·python·pandas
zzwq.1 天前
Pandas读取数据:csv、excel、sql全攻略
python·pandas
zfan5202 天前
python对Excel数据处理(1)
python·excel·pandas
l1t2 天前
用wsl自带的python 3.10下载适用于3.12的pandas版本结合uv安装python 3.12模拟离线安装场景
python·pandas·uv
qq_283720053 天前
Python 数据分析:Pandas+NumPy 超详细教程
python·数据分析·pandas
zzwq.4 天前
数据分析三件套:Numpy、Pandas、Matplotlib
数据分析·numpy·pandas
七颗糖很甜4 天前
雨滴谱数据深度解析——从原始变量到科学产品的Python实现【下篇】
python·算法·pandas