title: Changing an index column name of a csv file inside a for loop
body: <p>I have several <code>csv</code> files whose 1st <code>index</code> [0] retrieves &quot;Unnamed:0&quot; and I'd like to change this column to &quot;date&quot; inside a <code>for loop</code>. The function I created has a for loop that is essentially doing this: 1) retrieving the data I want, 2) turn it into a <code>dataframe</code>, 3) change the 1st column from Unnamed:0 to date and 4) turn the <code>dataframes</code> into <code>csv</code> files to a directory.</p>
  <p>This is the code</p>
  <pre><code>def custom_stock_data (ticker):
      for symbol in ticker:
          ticker_data = pd.DataFrame(get_data(symbol, start_date = &quot;05/25/2021&quot;, end_date = &quot;07/30/2021&quot;, interval = &quot;1d&quot;))
          ticker_data = ticker_data.rename(columns={'Unnamed:0':'date'}, inplace= True)
          ticker_csv = ticker_data.to_csv(r&quot;C:\xampp\htdocs\estagio\data_{}.csv&quot;.format(symbol))
          print(ticker_data)
  custom_stock_data([&quot;AMZN&quot;])
  </code></pre>
  <p>This is the CSV output:</p>
  <pre><code>Unnamed: 0     open         high         low          close  
  
  2021-05-25     3266.669922  3279.820068  3213.760010  3259.050049 
  </code></pre>
  <p>I'm getting two types of errors:</p>
  <p>When I execute the function <code>custom_stock_data</code> I get an indentation error on the line <code>            ticker_data = ticker_data.rename(columns={'Unnamed:0':'date'}, inplace= True)</code> (Inconsistent use of tabs and spaces in indentation. The tab is automatically created when I press <code>Enter</code> from the previous line, so I don't understand why it is giving this indentation error</p>
  <p>The 2nd error is after executing the <code>custom_stock_data(&quot;AMZN&quot;)</code>. The terminal retrieves &quot;Local variable 'ticker data' referenced before assignment&quot;.</p>
  <p>I was hoping that by calling <code>ticker_data</code> inside the for loop the 2nd time I could change all the &quot;Unnamed&quot; columns in the dataframe to &quot;date&quot;</p>