title: Pandas: Merging rows with the same index, while creating a new column
body: <p>I just started using Pandas and have a dataframe containing multiple rows with the same indexing, indicating a variable has certain features, e.g. </p>
  
  <pre><code>ItemID       Property    Numerical_value
  A1           'Red'       10     
  A1           'Fruit'     0
  B1           'Red'       25
  C1           'Liquid'    0
  </code></pre>
  
  <p>The assumptions holding for my data are; 
  Only rows where the property is 'Red' have a numerical value. And
  if an item has the property 'Fruit' it also has the property Red. </p>
  
  <p>The issue I'm facing is transforming this dateframe to follow a one-hot encoding scheme for each of the itemID's while also saving the numerical value if it's present, e.g.;</p>
  
  <pre><code>ItemID       Red&amp;Fruit   Just_red  Other  Numerical_value
  A1           1           0         0      10         
  B1           0           1         0      25
  C1           0           0         1      0
  </code></pre>
  
  <p>Currently, I have written the following code;</p>
  
  <pre><code>def read_report:
      fp = 'file_path'
      df = (pd.read_csv(fp))
      group = df.groupby('ItemID')['Property','Numerical_value'].apply(test_function)
  </code></pre>
  
  <p>with </p>
  
  <pre><code>def test_function(df):
      if 'Fruit' in df.values:
         num_val = df[df['Property'] == 'Red']['Numerical_value'].values[0]
         return pd.Series({'Red&amp;Fruit': '1', 'Num_val': num_val})
      elif 'Red' in df.values:
         num_val= df[df['Property'] == 'Red']['Num_val'].values[0]
         return pd.Series({'Just_red': '1', 'Num_val': num_val})
      else:
         return pd.Series({'Other': '1', 'Num_val': 0})
  </code></pre>
  
  <p>This does not seem to be optimal, especially the way to get the numerical value for each summarized row feels rather hacky.</p>
  
  <p>Is there a better way to achieve the same result?</p>