# How do I get a list (NOT plot/figure/pdf) of highest expressed genes in scanpy?

**URL:** <https://discourse.scverse.org/t/how-do-i-get-a-list-not-plot-figure-pdf-of-highest-expressed-genes-in-scanpy/565>\
**Category:** scanpy\
**Created:** [June 23, 2022, 9:42am UTC](https://discourse.scverse.org/t/how-do-i-get-a-list-not-plot-figure-pdf-of-highest-expressed-genes-in-scanpy/565 "2022-06-23T09:42:38Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Felix](https://avatars.discourse-cdn.com/v4/letter/f/aeb1de/32.png) [@Felix](https://discourse.scverse.org/u/Felix)\
**Post date:** [June 23, 2022, 9:42am UTC](https://discourse.scverse.org/t/how-do-i-get-a-list-not-plot-figure-pdf-of-highest-expressed-genes-in-scanpy/565/1 "2022-06-23T09:42:38Z")

</div>

Scanpy has a great function for plotting the highest expressed genes.

`sc.pl.highest_expr_genes()`

How do I get a LIST of these highest expressed genes please?

---

<div class="post-metadata">

**Author:** ![jeskowagner](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.scverse.org/jeskowagner/32/218_2.png) [@jeskowagner](https://discourse.scverse.org/u/jeskowagner)\
**Post date:** [June 29, 2022, 9:02am UTC](https://discourse.scverse.org/t/how-do-i-get-a-list-not-plot-figure-pdf-of-highest-expressed-genes-in-scanpy/565/2 "2022-06-29T09:02:37Z")

</div>

Hi Felix,

Are you looking for something similar to this?:

> **[Highest\_expr\_genes in table](https://scanpy.discourse.group/t/highest-expr-genes-in-table/92)**
>
> I analyzed highest\_expr\_genes by coding sc.pl.highest\_expr\_genes(adata, n\_top=100). I got plot Fig, but I would like to get these genes and expression levels in a Table. Could you tell me how should I do?

Cheers,  
Jesko

---

<div class="post-metadata">

**Author:** ![Felix](https://avatars.discourse-cdn.com/v4/letter/f/aeb1de/32.png) [@Felix](https://discourse.scverse.org/u/Felix)\
**Post date:** [July 8, 2022, 5:56am UTC](https://discourse.scverse.org/t/how-do-i-get-a-list-not-plot-figure-pdf-of-highest-expressed-genes-in-scanpy/565/3 "2022-07-08T05:56:44Z")

</div>

Yes!!

This worked for me with a few modifications shown below.

Thank you! 😊

```auto
    # normalize counts matrix so that each 'cell' (barcode) has counts summing to 1
    adata.X_norm = sc.pp.normalize_total(adata, target_sum=1, inplace=False)['X']
    
    # create new adata.var column contaning mean of each column of adata.X_norm above
    # this is total normalized counts per gene a.k.a. 'mean_total_expression'
    adata.var['mean_expression'] = np.ravel(adata.X_norm.mean(0))
    
    # return pd.DataFrame of n top-ranked genes by mean expression
    x = pd.DataFrame(adata.var.nlargest(n, 'mean_expression')['mean_expression'])

```

---

<div class="post-metadata">

**Author:** ![jeskowagner](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.scverse.org/jeskowagner/32/218_2.png) [@jeskowagner](https://discourse.scverse.org/u/jeskowagner)\
**Post date:** [July 8, 2022, 7:57am UTC](https://discourse.scverse.org/t/how-do-i-get-a-list-not-plot-figure-pdf-of-highest-expressed-genes-in-scanpy/565/4 "2022-07-08T07:57:43Z")

</div>

Nice! Glad that worked and thanks for sharing your code, hopefully it’ll help others looking to do the same thing in the future.
