2

I have a dataframe with four columns. In the column 'Regime' there are 2 groups (Ctrl and FR). I would like to create an array where the rows are the replications, and the columns the values based on the ligt regime. divide the column Value based on the column Regime and make two new columns: Value_Ctrl and Value_FR.

This is how the original dataframe looks like:

Replication   Regime     Value
 1          Ctrl          2
 2          Ctrl          7
 3          Ctrl          1
 4          Ctrl          5
 1          FR           12
 2          FR           22
 3          FR           52
 4          FR           22

I would like to have

data = np.array[2, 12
                7, 22
                1, 52, 
                5, 22]


                               

3 Answers 3

2

Use DataFrame.pivot with DataFrame.to_numpy:

a = df.pivot('Replication','Regime','Value').to_numpy()
print (a)
[[ 2 12]
 [ 7 22]
 [ 1 52]
 [ 5 22]]
Sign up to request clarification or add additional context in comments.

Comments

1

Try this please:

df.groupby('Replication').agg({'Value': list}).values

Comments

0

df1 = df[df[1] == 'CTRL']

df2 = df[df[1] == 'FR']

m = pd.merge(df1,df2,on=0)

Then delete the unnecessary columns

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.