title: How to convert Series to class float
body: <p>I am learning Python and right now I am trying to examine percent change in stock values from a database. However, one of the variables I am trying to examine is coming from a database which is of type Series. And whenever I try to convert into a float to use it for multiplication and division, I receive an error "TypeError: cannot convert the series to ". I have seen solutions that stated to use .astype(float), but that didn't work for me. Any help would be appreciated.</p>
  
  <pre><code>import pandas as pd
  import os
  import time
  from datetime import datetime
  
  
  path = "C:/Users/andre/AppData/Local/Programs/Python/Python37/SciKit-learn Tutorial/intraQuarter"
  
  def Key_Stats(gather = "Total Debt/Equity (mrq)"): 
      statspath = path + '/_KeyStats'
      stock_list = [x[0] for x in os.walk(statspath)]
      counter = 0
      df = pd.DataFrame(columns = ['Date','Unix','Folder','DE Ratio','Price',
                                   'Stock_pct_change','SP500','SP500_pct_change', 'Difference'])
  
      sp500_df = pd.read_csv("YAHOO-INDEX_GSPC.csv")
      ticker_list = []
  
  
      for each_dir in stock_list[1:]:
          each_file = os.listdir(each_dir)
          folder = each_dir.split("\\")[1]
          ticker_list.append(folder)
  
          #Reset starting point for each directory
          starting_stock_value = False
          starting_sp500_value = False
  
          if len(each_file) &gt; 0:
              for file in each_file:
                  date_stamp = datetime.strptime(file, '%Y%m%d%H%M%S.html')
                  unix_time = time.mktime(date_stamp.timetuple())
                  full_file_path = each_dir + '/' + file
  
                  file_content_source = open(full_file_path, 'r').read()
  
                  try:
                      value = file_content_source.split(gather)[1].split('&lt;td class="yfnc_tabledata1"&gt;')[1].split('&lt;/td&gt;')[0]
  
                      try:
                          sp500_date = datetime.fromtimestamp(unix_time).strftime('%Y-%m-%d')
                          row = sp500_df[(sp500_df['Date'] == sp500_date)] 
                          sp500_value = row['Adj Close']
                          print(type(sp500_value))
                          print(sp500_value)
                      except:    
                          sp500_date = datetime.fromtimestamp(unix_time-259200).strftime('%Y-%m-%d')
                          row = sp500_df[(sp500_df['Date'] == sp500_date)] 
                          sp500_value = row['Adj Close']
  
                      try:
                          stock_price = file_content_source.split('&lt;/small&gt;&lt;big&gt;&lt;b&gt;')[1].split('&lt;/b&gt;&lt;/big&gt;')[0]
                          if(stock_price.endswith('&lt;/span&gt;')):
                             stock_price = stock_price.split('&gt;')[1].split('&lt;/span')[0]
                      except IndexError:
                          try:
                              stock_price = file_content_source.split('&lt;/small&gt;&lt;big&gt;&lt;b&gt;')[1].split('&lt;/span&gt;')[0].split('&gt;')[1]
                          except IndexError:   
                              try:
                                  stock_price = file_content_source.split('&lt;span id="yfs_')
                                  seglist = [] #Created a list to store all the possible numbers that arise
                                  for parts in stock_price:
                                      segment = parts.split('&lt;/span&gt;')[0].split('&gt;')[1]
                                      try:
                                          #The numbers are usually 4,5, or 6 characters in length and check if str is a number
                                          if((len(segment) == 4 or len(segment) == 5 or len(segment) == 6) and float(segment) &gt;= 0):
                                              seglist.append(segment) #Add potential number to list
                                              stock_price = seglist[0] #Noticed the first number is usually the correct one
                                      except ValueError:
                                          pass
                              except IndexError:
                                  print('Error in Folder:', folder, ' File: ', file, ' Stock Price=', stock_price)
  
                      #print('Folder:', folder, ' File', file, ' Stock Price: ', stock_price)
  
                      if not starting_stock_value:
                          starting_stock_value = float(stock_price)
                      if not starting_sp500_value:
                          starting_sp500_value = float(sp500_value)
  
                      #percentage change = (new-old)/old x 100
                      stock_pct_change = ((float(stock_price) - starting_stock_value) / starting_stock_value) * 100
  
     #-------------------------------------------------------------------------------
                      #ERROR OCCURS HERE!!!!
                      sp500_pct_change = ((float(sp500_value) - starting_sp500_value) / starting_sp500_value) * 100
  
     #-------------------------------------------------------------------------------
  
                      df = df.append({'Date': date_stamp,'Unix': unix_time,
                                      'Folder': folder,'DE Ratio': value,
                                      'Price': stock_price,
                                      'Stock_pct_change': stock_pct_change,
                                      'SP500': sp500_value,
                                      'SP500_pct_change': sp500_pct_change,
                                      'Difference': stock_pct_change-sp500_pct_change},
                                     ignore_index = True)
                  except IndexError:
                      stock_price = file_content_source.split('&lt;span id="yfs_')[5].split('&lt;/span&gt;')[0].split('&gt;')[1]
                      print('Error in Folder:', folder, ' File: ', file, "Value=", value, 'Stock Price=', stock_price)
  
      #Plot
      for each_ticker in ticker_list:
          try:
              plot_df = df[(df['Folder'] == each_ticker)]
              plot_df = plot_df.set_index(['Date'])
  
              plot_df['Difference'].plot(label = each_ticker)
              plt.legend()
          except:
              pass
  
      plt.show()
  
  
  Key_Stats()
  </code></pre>
  
  <p>Error:</p>
  
  <pre><code>&lt;class 'pandas.core.series.Series'&gt;
  2997    1131.130005
  Name: Adj Close, dtype: float64
  &lt;class 'pandas.core.series.Series'&gt;
  2947    1129.439941
  Name: Adj Close, dtype: float64
  &lt;class 'pandas.core.series.Series'&gt;
  2778    1198.680054
  Name: Adj Close, dtype: float64
  &lt;class 'pandas.core.series.Series'&gt;
  Series([], Name: Adj Close, dtype: float64)
  Traceback (most recent call last):
    File "C:\Users\andre\AppData\Local\Programs\Python\Python37\SciKit-learn Tutorial\Tutorial 6 - Playing with the Data (pct_change).py", line 103, in &lt;module&gt;
      Key_Stats()
    File "C:\Users\andre\AppData\Local\Programs\Python\Python37\SciKit-learn Tutorial\Tutorial 6 - Playing with the Data (pct_change).py", line 83, in Key_Stats
      sp500_pct_change = ((float(sp500_value) - starting_sp500_value) / starting_sp500_value) * 100
    File "C:\Users\andre\AppData\Local\Programs\Python\Python37\lib\site-packages\pandas\core\series.py", line 93, in wrapper
      "{0}".format(str(converter)))
  TypeError: cannot convert the series to &lt;class 'float'&gt;
  </code></pre>