I have three groups of rows right now and I am trying to combine those groups of rows into single rows. Current State of Data (Image only shows two genes, but I promise there's a third)
I have three separate genes, each having 61 NX values associated with them. I am trying to combine the 61 rows for each gene into a single row for each gene with all of its NX values listed across the row so that I can easily find the mean. I have no idea how to go about this. Please help.
Here is my code thus far if it matters.
import pandas as pd
df = pd.read_csv('rna_consensus.tsv', delimiter='\t')
df = df[df['Gene name'].isin(["ENPP4", "RAD52", "ICA1"])]
df = df[['Gene name', 'NX']]
可以使用.groupby()
和GroupBy.mean()
直接得到NX
分组和Gene name
的均值,如下:
df.groupby('Gene name', as_index=False)['NX'].mean()
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.