title: pandas subtract two sets of data
body: <p>I am trying to figure out why if I subtract two sets of data it gives me NaN errors. I want to do an element-by-element subtraction and I have successfully extracted two separate sets but when I try to do anything with it, it keeps giving me NaN errors</p>
  
  <p>Here is my code:</p>
  
  <pre><code>import pandas as pd
  import numpy as np
  import matplotlib.pyplot as plt
  
  filename = 'vc_test.csv'
  headings = 'injection', 'treatment','filename', 'l0', 'l1', 'l2', 'l3', 'filename', 'r0', 'r1', 'r2', 'r3'
  
  #import data
  df = pd.read_csv(filename, names=headings)
  
  
  
  
  #convert values to floats
  df['l0'] = df['l0'].astype(float)
  df['l1'] = df['l1'].astype(float)
  df['l2'] = df['l2'].astype(float)
  df['l3'] = df['l3'].astype(float)
  df['r0'] = df['r0'].astype(float)
  df['r1'] = df['r1'].astype(float)
  df['r2'] = df['r2'].astype(float)
  df['r3'] = df['r3'].astype(float)
  
  #group by injection so you have 2 subgroups
  df.groupby(['injection'])
  
  #subtract and assign to a different array to normalize data to baseline
  df_os, df_od = df[['l1','l2','l3']].sub(df['l0'], axis=0), df[['r1','r2','r3']].sub(df['r0'], axis=0)
  
  print df_os
  print df_od
  
  ioc = df_os - df_od
  print ioc
  </code></pre>
  
  <p>I have also tried df.sub() but it didn't work. Please help...</p>