python - Divide all rows in a pandas dataframe by a specific row -
i have pandas dataframe below:
sample_name c14-cer_mean c16-cer_mean c18-cer_mean c18:1-cer_mean 0 1 1 0.124749 0.285659 35.302029 8.173144 1 1 10 0.332976 0.656197 39.220933 6.446620 2 1 13 0.227423 0.272440 26.866943 5.763723 3 1 14 0.128359 0.604903 29.848169 6.801633 4 1 5 0.204000 0.242652 21.354158 4.637632 5 1 6 0.122697 0.412868 25.168258 5.866785 6 1 9 0.161679 0.569781 28.707720 6.525267 7 blank 0.408713 0.526573 0.531430 0.111025
i want dataframe values in rows have been divided values in row sample_name "blank" (normalizing sample "blank"). how can achieve in pandas?
you can select rows , slice df using loc
, call div
, pass last row using iloc[-1]
:
in [58]: df.loc[:,'c14-cer_mean':] = df.loc[:,'c14-cer_mean':].div(df.iloc[-1]['c14-cer_mean':]) df out[58]: sample_name c14-cer_mean c16-cer_mean c18-cer_mean c18:1-cer_mean index 0 1 1 0.305224 0.542487 66.4284 73.6153 1 1 10 0.814694 1.24617 73.8026 58.0646 2 1 13 0.556437 0.517383 50.5559 51.9137 3 1 14 0.314057 1.14875 56.1658 61.2622 4 1 5 0.499128 0.460814 40.1824 41.7711 5 1 6 0.300203 0.784066 47.3595 52.842 6 1 9 0.395581 1.08206 54.0198 58.773 7 blank 1 1 1 1
Comments
Post a Comment