I am trying to create a dataframe from my data (estimates between chemicals and proteins) using pandas in python.
I want the proteins that have the most cases to be displayed in my framework first, so I sorted my data earlier. But when I do a dataframe, it does not get the expected result.
Here is an example of my data:
chemicals prots scores
CID000000006 10116.ENSRNOP00000003921 196
CID000000051 10116.ENSRNOP00000003921 246
CID000000085 10116.ENSRNOP00000003921 196
CID000000119 10116.ENSRNOP00000003921 247
CID000000134 10116.ENSRNOP00000008952 159
CID000000135 10116.ENSRNOP00000008952 157
CID000000174 10116.ENSRNOP00000008952 439
CID000000175 10116.ENSRNOP00000001021 858
CID000000177 10116.ENSRNOP00000004027 760
As you can see, "10116.ENSRNOP00000003921" is the protein with the largest amount in my data.
So, I would like to get something like:
10116.ENSRNOP00000003921 10116.ENSRNOP00000008952
CID000000006 196
CID000000051 246
CID000000085 196
CID000000119 247
CID000000134 159
CID000000135 157
CID000000174 439
And here is my code:
import pandas as pd
df_rat= pd.read_csv("dt_matrix_rat.csv",sep="\t", header=True)
df_rat.columns = ['chemicals','proteins','scores']
df_rat1 = df_rat.pivot(index='chemicals', columns='proteins', values='scores')
df_rat1.to_csv("rat_matrix.csv", sep='\t', index=True )
source
share