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