title: Cant properly pivot a dataframe coming from a .csv file
body: <p>My goal is to reorder a dataframe for my convenience. When I set the dataframe &quot;manually&quot; I can do it without problems. But when I try after reading a <code>.csv</code> file, it fails. I will explain better with the examples:</p>
  <p><strong>&quot;Manual&quot; Dataframe:</strong></p>
  <ul>
  <li>I import <code>pandas</code></li>
  <li>Then I declare the dataframe I will be working with.</li>
  <li>I reorder the table as I wish it to be.</li>
  <li>Finally I see the results.</li>
  </ul>
  <p>And here is the code:</p>
  <pre><code>import pandas as pd
  
  df = pd.DataFrame({'Mes': ['Enero', 'Enero', 'Enero', 'Febrero', 'Febrero', 'Febrero'],
                     'Anio': ['2019', '2020', '2021', '2019', '2020', '2021'],
                     'Ventas': [2, 3, 4, 5, 6, 7],})
  print(df)
  
  df_ventas = df.pivot(index='Mes', columns='Anio', values='Ventas')
  print(df_ventas)
  </code></pre>
  <p>The result is exactly what I want, I table that went from this:</p>
  <pre><code>       Mes   Anio  Ventas
  0    Enero  2019       2
  1    Enero  2020       3
  2    Enero  2021       4
  3  Febrero  2019       5
  4  Febrero  2020       6
  5  Febrero  2021       7
  </code></pre>
  <p>To this:</p>
  <pre><code>Anio      2019  2020  2021
  Mes
  Enero       2     3     4
  Febrero     5     6     7
  </code></pre>
  <p><strong><code>.csv</code> file:</strong></p>
  <pre><code>import pandas as pd
  
  data = pd.read_csv(&quot;archivo.csv&quot;)
  
  df_ventas = data.pivot(index = &quot;Mes&quot; , columns = &quot;Anio&quot;, values = &quot;Ventas&quot;)
  print(df_ventas)
  </code></pre>
  <p>The <code>.csv</code> file has the same info, but the result is the following:</p>
  <pre><code>Traceback (most recent call last):   
      File &quot;D:\Usuarios\wrodriguez\AppData\Local\Programs\Python\Python39\lib\site-packages\pandas\core\indexes\base.py&quot;, line 3361, in get_loc
          return self._engine.get_loc(casted_key)   
      File &quot;pandas\_libs\index.pyx&quot;, line 76, in pandas._libs.index.IndexEngine.get_loc   
      File &quot;pandas\_libs\index.pyx&quot;, line 108, in
          pandas._libs.index.IndexEngine.get_loc   
      File &quot;pandas\_libs\hashtable_class_helper.pxi&quot;, line 5198, in
          pandas._libs.hashtable.PyObjectHashTable.get_item   
      File &quot;pandas\_libs\hashtable_class_helper.pxi&quot;, line 5206, in
          pandas._libs.hashtable.PyObjectHashTable.get_item KeyError: 'Anio'
  
  The above exception was the direct cause of the following exception:
  
  Traceback (most recent call last):   
      File &quot;D:\Usuarios\wrodriguez\Downloads\Codigos_Prueba_Python_RobotFramework\02_Vulgara\06_Graficas\01.py&quot;, line 10, in &lt;module&gt;
          df_ventas = data.pivot(index = &quot;Mes&quot; , columns = &quot;Anio&quot;, values = &quot;Ventas&quot;)   
      File &quot;D:\Usuarios\wrodriguez\AppData\Local\Programs\Python\Python39\lib\site-packages\pandas\core\frame.py&quot;, line 7793, in pivot
          return pivot(self, index=index, columns=columns, values=values)   
      File &quot;D:\Usuarios\wrodriguez\AppData\Local\Programs\Python\Python39\lib\site-packages\pandas\core\reshape\pivot.py&quot;, line 505, in pivot
          data_columns = [data[col] for col in columns_listlike]
      File &quot;D:\Usuarios\wrodriguez\AppData\Local\Programs\Python\Python39\lib\site-packages\pandas\core\reshape\pivot.py&quot;, line 505, in &lt;listcomp&gt;
          data_columns = [data[col] for col in columns_listlike]    
      File &quot;D:\Usuarios\wrodriguez\AppData\Local\Programs\Python\Python39\lib\site-packages\pandas\core\frame.py&quot;, line 3458, in __getitem__
          indexer = self.columns.get_loc(key)    
      File &quot;D:\Usuarios\wrodriguez\AppData\Local\Programs\Python\Python39\lib\site-packages\pandas\core\indexes\base.py&quot;, line 3363, in get_loc
          raise KeyError(key) from err KeyError: 'Anio'
  </code></pre>
  <p>I have been researching but I can't find anything that helps to understand why it cant be read as I did manually.</p>