title: How to replace spaces with underscores in a multiindexed pandas dataframe (pandas 1.0)
body: <p>I want to replace spaces with underscores in the column names of a multi-indexed pandas dataframe but the method I have being using with regular pandas dataframe does not work and I am searching for a solution.</p>
  
  <p>For a reproducible example I provide some data:</p>
  
  <pre><code>df_pivot.to_json()
  '{"(\'Open Interest\', \'cu2003\')":{"1582016340553":0.0,"1582016340553":0.0},"(\'Open Interest\', \'cu2004\')":{"1582016340553":0.0,"1582016340553":0.0},"(\'Open Interest\', \'cu2005\')":{"1582016340553":0.0,"1582016340553":0.0},"(\'Open Interest\', \'cu2006\')":{"1582016340553":0.0,"1582016340553":0.0},"(\'Open Interest\', \'cu2007\')":{"1582016340553":0.0,"1582016340553":0.0}}'
  </code></pre>
  
  <p>My initial attempt was:</p>
  
  <pre><code>df_pivot.columns = df_pivot.columns.str.replace(' ', '_')
  
  ---------------------------------------------------------------------------
  AttributeError                            Traceback (most recent call last)
  &lt;ipython-input-153-c1c5f88f6ecd&gt; in &lt;module&gt;
  ----&gt; 1 df_pivot.columns = df_pivot.columns.str.replace(' ', '_')
  
  ~\Anaconda3\envs\tf2\lib\site-packages\pandas\core\accessor.py in __get__(self, obj, cls)
      185             # we're accessing the attribute of the class, i.e., Dataset.geo
      186             return self._accessor
  --&gt; 187         accessor_obj = self._accessor(obj)
      188         # Replace the property with the accessor object. Inspired by:
      189         # http://www.pydanny.com/cached-property.html
  
  ~\Anaconda3\envs\tf2\lib\site-packages\pandas\core\strings.py in __init__(self, data)
     2032 
     2033     def __init__(self, data):
  -&gt; 2034         self._inferred_dtype = self._validate(data)
     2035         self._is_categorical = is_categorical_dtype(data)
     2036         self._is_string = data.dtype.name == "string"
  
  ~\Anaconda3\envs\tf2\lib\site-packages\pandas\core\strings.py in _validate(data)
     2069         if isinstance(data, ABCMultiIndex):
     2070             raise AttributeError(
  -&gt; 2071                 "Can only use .str accessor with Index, not MultiIndex"
     2072             )
     2073 
  
  AttributeError: Can only use .str accessor with Index, not MultiIndex
  </code></pre>