Export DEG file containing 'names', 'logfoldchanges', 'pvals_adj', 'pts' for each leiden cluster after sc.tl.rank_genes_groups


When exporting DEGs

sc.tl.rank_genes_groups(adata, 'leiden', method='wilcoxon', pts=True)
sc.pl.rank_genes_groups(adata, n_genes=25, sharey=False)
result = adata.uns['rank_genes_groups']
groups = result['names'].dtype.names
degs_by_cluster = pd.DataFrame({group + '_' + key[:1]: result[key][group]
    for group in groups for key in ['names', 'logfoldchanges', 'pvals_adj']})

how to add the sorted “pts” columns to the data, so that the eventual .csv file contains [‘names’, ‘logfoldchanges’, ‘pvals_adj’, ‘pts’] columns for each of the leiden clusters?

Many thanks!