Subtract a column in pandas dataframe by its first value
<p>I need to subtract all elements in one column of pandas dataframe by its first value.</p>

<p>In this code, pandas complains about self.inferred_type, which I guess is the circular referencing.</p>

<pre><code>df.Time = df.Time - df.Time[0]
</code></pre>

<p>And in this code, pandas complains about setting value on copies.</p>

<pre><code>df.Time = df.Time - df.iat[0,0]
</code></pre>

<p>What is the correct way to do this computation in Pandas?</p>

<p>I think you can select first item in column <code>Time</code> by <a href="http://pandas.pydata.org/pandas-docs/stable/generated/pandas.Series.iloc.html" rel="nofollow"><code>iloc</code></a>:</p>

<pre><code>df.Time = df.Time - df.Time.iloc[0]
</code></pre>

<p>Sample:</p>

<pre><code>start = pd.to_datetime('2015-02-24 10:00')
rng = pd.date_range(start, periods=5)

df = pd.DataFrame({'Time': rng, 'a': range(5)})  
print (df)
                 Time  a
0 2015-02-24 10:00:00  0
1 2015-02-25 10:00:00  1
2 2015-02-26 10:00:00  2
3 2015-02-27 10:00:00  3
4 2015-02-28 10:00:00  4

df.Time = df.Time - df.Time.iloc[0]
print (df)
    Time  a
0 0 days  0
1 1 days  1
2 2 days  2
3 3 days  3
4 4 days  4
</code></pre>

<p>Notice:</p>

<p>For me works perfectly your 2 ways also.</p>

python datetime pandas time subtraction