title: Move column values to values with True/False
body: <p>I have a dataset similar to this one:</p>
  
  <pre><code> data = {'lat': [0.15, 0.15, 0.15, 0.15, 0.25, 0.25, 0.48, 0.48, 0.48, 0.48],
          'lon': [0.87, 0.87, 0.87, 0.87, 0.12, 0.12, 0.59, 0.59, 0.59, 0.59],
          'animal': ['dog', 'cat', 'rat', 'rat', 'cat', 'rat', 'cat', 'dog', 'dog', 'rat'],
          'category': ['A', 'C', 'B', 'C', 'B', 'B', 'C', 'A', 'C', 'C']}
  mdf = pd.DataFrame(data)
  
  mdf
  Out[460]: 
      lat   lon animal category
  0  0.15  0.87    dog        A
  1  0.15  0.87    cat        C
  2  0.15  0.87    rat        B
  3  0.15  0.87    rat        C
  4  0.25  0.12    cat        B
  5  0.25  0.12    rat        B
  6  0.48  0.59    cat        C
  7  0.48  0.59    dog        A
  8  0.48  0.59    dog        C
  9  0.48  0.59    rat        C
  </code></pre>
  
  <p>I want to use 'animal', 'lat' and 'lon' as some kind of indexes to obtain something like this:</p>
  
  <pre><code>      lat   lon animal     A      B      C
  0    0.15  0.87    dog True   False  False
  1    0.15  0.87    cat False  False  True
  2    0.15  0.87    rat False  True   True
  4    0.25  0.12    cat False  True   False
  5    0.25  0.12    rat False  True   False
  6    0.48  0.59    cat False  False  True
  7    0.48  0.59    dog True   False  True
  9    0.48  0.59    rat False  False  True
  </code></pre>
  
  <p>I don't really care wether it is True/False, 1/0, etc. as long as I can see which categories each combination of 'lat', 'long' and 'animal' has.</p>
  
  <p>I've been trying without success several alternatives: pivot, pivot_table, groupby, stack/unstack... but none seems to answer my needs.</p>
  
  <p>The only option I have left is to iterate through the different 'lat', 'lon', 'animal' alternatives and check wether there is an occurence for each of the 'category'.</p>
  
  <p>Maybe this could be done somehow by defining 'lat', 'lon', 'animal' as indexes and "unmelting" somehow </p>
  
  <p>Any suggestions?</p>
  
  <p>Thanks.</p>
  
  <hr>
  
  <p>EDIT: I am unable to have new lines in comments, and I don't know how to contact the person that closed the post, so let me bring some additional explanation here. Apologies for the annoyance.</p>
  
  <p>Quang, thanks for your reference to a different thread. However, I am not sure it helps me.</p>
  
  <p>I could do this:</p>
  
  <pre><code>pd.get_dummies(mdf['category'], prefix='', prefix_sep='')
  </code></pre>
  
  <p>But I get my initial 10 lines instead of the table I was aiming at.</p>
  
  <p>To obtain something useful with get_dummies, I would have to do this:</p>
  
  <pre><code>mdf = mdf.join(pd.get_dummies(mdf['category'], prefix='', prefix_sep=''))
  mdf[['A', 'B', 'C']] = mdf.groupby(['lat', 'lon', 'animal'])[['A', 'B', 'C']].transform('sum')
  mdf.drop_duplicates(subset=['lat', 'lon', 'animal'], inplace=True)
  d = {1: True,
       0: False}
  mdf[['A', 'B', 'C']] = mdf[['A', 'B', 'C']].replace(d)
  mdf.drop('category',
          axis=1,
          inplace=True)
  </code></pre>
  
  <p>But this seems overcomplicated and I feel there must have a better way...</p>
  
  <p>I also thought about this:</p>
  
  <pre><code>mdf['value'] = [True] * 10
  mdf = mdf.set_index(['lat', 'lon', 'animal', 'category'])
  mdf = mdf.unstack(fill_value=False)
  mdf = mdf.reset_index()
  mdf.columns = ['lat', 'lon', 'animal', 'A', 'B', 'C']
  </code></pre>
  
  <p>But again, it seems so un-pythonic to trick the system by playing with indexes...</p>
  
  <p>There must surely be a better way!</p>
  
  <p>Thanks.</p>