I have the following pandas data frame:
import pandas as pd import numpy as np df = pd.DataFrame({ \'fc\': [100,100,112,1.3,14,125],
you can also use pd.crosstab() method:
In [82]: pd.crosstab(index=df.gene_symbol, columns=df.sample_id, values=df.fc, aggfunc='mean') \ ...: .rename_axis(None,1) \ ...: .reset_index() ...: Out[82]: gene_symbol S1 S2 0 a 100.0 1.3 1 b 100.0 14.0 2 c 112.0 125.0