title: Pandas set element style dependent on another dataframe mith multi index
body: <p>I have previously asked the question <a href="https://stackoverflow.com/questions/47912420/pandas-set-element-style-dependent-on-another-dataframe">Pandas set element style dependent on another dataframe</a>, which I have a working solution to, but now I am trying to apply it to a data frame with a multi index and I am getting an error, which I do not understand.</p>
  
  <h2>Problem</h2>
  
  <p>I have a pandas df and accompanying boolean matrix.  I want to highlight the df depending on the boolean matrix.</p>
  
  <h2>Data</h2>
  
  <pre><code>import pandas as pd
  import numpy as np
  from datetime import datetime
  
  date = pd.date_range(start = datetime(2016,1,1), end = datetime(2016,2,1), freq = "D")
  i = len(date)
  dic = {'X':pd.DataFrame(np.random.randn(i, 2),index = date, columns = ['A','B']),
         'Y':pd.DataFrame(np.random.randn(i, 2),index = date, columns = ['A','B']),
         'Z':pd.DataFrame(np.random.randn(i, 2),index = date, columns = ['A','B'])}
  df = pd.concat(dic.values(),axis=1,keys=dic.keys())
  
  
  boo =  [True, False]
  bool_matrix = {'X':pd.DataFrame(np.random.choice(boo, (i,2), p=[0.3,.7]), index = date, columns = ['A','B']),
                 'Y':pd.DataFrame(np.random.choice(boo, (i,2), p=[0.3,.7]), index = date, columns = ['A','B']),
             'Z':pd.DataFrame(np.random.choice(boo, (i,2), p=[0.3,.7]), index = date, columns = ['A','B'])}
  
  bool_matrix =pd.concat(bool_matrix.values(),axis=1,keys=bool_matrix.keys())
  </code></pre>
  
  <h2>My attempted solution</h2>
  
  <pre><code>def highlight(value):
      return 'background-color: green' 
  my_style = df.style
  for column in df.columns:
      for i in df[column].index:
          data = bool_matrix.loc[i, column]
          if data: 
              my_style = df.style.use(my_style.export()).applymap(highlight, subset = pd.IndexSlice[i, column])
  
  my_style
  </code></pre>
  
  <h2>Results</h2>
  
  <p>The above throws an <code>AttributeError: 'Series' object has no attribute 'applymap'</code></p>
  
  <p>I do not understand what is returning as a Series.  This is a single value I am subsetting and this solution worked for non multi-indexed df's as shown below.</p>
  
  <h2>Without Multi-index</h2>
  
  <pre><code>import pandas as pd
  import numpy as np
  from datetime import datetime
  np.random.seed(24)
  date = pd.date_range(start = datetime(2016,1,1), end = datetime(2016,2,1), freq = "D")
  df = pd.DataFrame({'A': np.linspace(1, 100, len(date))})
  df = pd.concat([df, pd.DataFrame(np.random.randn(len(date), 4), columns=list('BCDE'))],
                 axis=1)
  
  df['date'] = date
  df.set_index("date", inplace = True)
  
  boo =  [True, False]
  bool_matrix = pd.DataFrame(np.random.choice(boo, (len(date), 5),p=[0.3,.7]), index = date,columns=list('ABCDE'))
  
  def highlight(value):
      return 'background-color: green' 
  my_style = df.style
  for column in df.columns:
      for i in bool_matrix.index:
          data = bool_matrix.loc[i, column]
          if data: 
              my_style = df.style.use(my_style.export()).applymap(highlight, subset = pd.IndexSlice[i,column])
  my_style
  </code></pre>
  
  <h2>Documentation</h2>
  
  <p>The <a href="https://pandas.pydata.org/pandas-docs/stable/style.html" rel="nofollow noreferrer">docs</a> make reference to CSS Classes and say that "Index label cells include level where k is the level in a MultiIndex."  I am obviouly indexing this wrong, but am stumped on how to proceed.</p>