compute mean of a column with python
<p>I have a dataframe df  : </p>

<pre><code>TIMESTAMP equipement1 equipement2
2016-05-10 13:20:00 0.000000 0.000000
2016-05-10 14:40:00 0.400000 0.500000
2016-05-10 15:20:00 0.500000 0.500000
</code></pre>

<p>I would like to compute for each equipmeentx the ratio when timestamp in [TS_min, TS_max]
For example function :    </p>

<pre><code>def ratio(df, 2016-05-10 14:40:00, 2016-05-10 15:20:00)
TIMESTAMP equipement1 equipement2
2016-05-10 14:40:00 0.4/(0.4+0.5) 0.5/(0.5+0.5)
2016-05-10 15:20:00 0.5/(0.4+0.5) 0.5/(0.5+0.5)
</code></pre>

<p>Any idea to help me please?</p>

<p>Thank you</p>

<p>Assuming TIMESTAMP is a datetime type, here is one way:</p>

<pre><code>df = df.set_index('TIMESTAMP')
r = df.ix['2016-05-10 14:40:00':'2016-05-10 15:20:00']
r/r.sum()

                     equipement1  equipement2
TIMESTAMP
2016-05-10 14:40:00     0.444444          0.5
2016-05-10 15:20:00     0.555556          0.5
</code></pre>

python pandas