Skip to content Skip to sidebar Skip to footer

Iterate Through Rows On Condition Pandas Python

I have an excel table that i read in by data = pd.read_excel('..data.xlsx') Block Concentration Name Replicate Value 1 100 A 1 1446 1

Solution 1:

You can use pivot_table:

In [11]: df
Out[11]:
    Block  Con Name  Replicate  Mean
0       1  100    A          1    20
1       1  100    A          2    10
2       1  100    A          3    30
3       1  100    B          1    40
4       1  100    B          2    12
5       1  100    B          3    23
6       1   33    A          1    56
7       1   33    A          2   234
8       1   33    A          3   377
9       1   33    B          1   434
10      1   33    B          2  1232
11      1   33    B          3   233

In [12]: df.pivot_table(index=["Block", "Con"], columns=["Name", "Replicate"], values="Mean")
Out[12]:
Name        A              B
Replicate   1    2    3    1     2    3
Block Con
1     33   56  234  377  434  1232  233
      100  20   10   30   40    12   23

Post a Comment for "Iterate Through Rows On Condition Pandas Python"