I have the following data frame:
import pandas as pd
source_df = pd.DataFrame({ 'gene':["foo","bar","qux","woz"], 'cell1':[5,9,1,7], 'cell2':[12,90,13,87]})
source_df = source_df[["gene","cell1","cell2"]]
It looks like this:
In [132]: source_df
Out[132]:
gene cell1 cell2
0 foo 5 12
1 bar 9 90
2 qux 1 13
3 woz 7 87
What I want to do is to sum all the numeric values, that should yield a single value
224
What's the way to do it?
I tried this but give two values instead:
In [134]: source_df.sum(numeric_only=True)
Out[134]:
cell1 22
cell2 202
dtype: int64
You need to call sum()
again. Example -
In [5]: source_df.sum(numeric_only=True).sum()
Out[5]: 224
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With