title: how to put data into Excel table with for loop pandas?
body: <p>I'm trying to put data in a table and convert it to an excel file but i can't get the table i want, the excel file contains just the last hotel in my list if anyone can help or explain what's the cause of it, this is the final output i want to get</p>
  <p><a href="https://i.stack.imgur.com/oP1Hp.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/oP1Hp.png" alt="enter image description here" /></a></p>
  <p>this the data i'm printing</p>
  <pre><code>Byzance Nabeul : Chambre Double - {'All Inclusive soft': ('208', '166', '25%'), 'Demi Pension': 138}
  Palmyra Club Nabeul Nabeul : Double Standard - {'All Inclusive soft': ('225', '180', '25%')}
  </code></pre>
  <p>and here is my code</p>
  <pre><code>#!/usr/bin/env python
  # coding: utf-8
  import time
  from time import sleep
  import ast
  import xlwt
  from selenium import webdriver
  from selenium.webdriver.support.ui import WebDriverWait, Select
  from selenium.common.exceptions import StaleElementReferenceException, NoSuchElementException
  from selenium.webdriver.support import expected_conditions as EC
  from selenium.webdriver.common.by import By
  import pandas as pd
  
  
  driver = webdriver.Chrome(&quot;C:\\Users\\marketing2\\Documents\\chromedriver.exe&quot;)
  driver.get('https://tn.tunisiebooking.com/')
  
  def exists(xpath):
          try:
              driver.find_element_by_id(xpath);
          except NoSuchElementException:
              return &quot;false&quot;
          else:
              return &quot;true&quot;
  
  # params to select
  params = {
      'destination': 'Nabeul',
      'date_from': '11/09/2021',
      'date_to': '12/09/2021',
      'bedroom': '1'
  }
  
  # select destination
  destination_select = Select(WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.ID, 'ville_des'))))
  destination_select.select_by_value(params['destination'])
  
  # select bedroom
  bedroom_select = Select(WebDriverWait(driver, 10).until(EC.element_to_be_clickable((By.ID, 'select_ch'))))
  bedroom_select.select_by_value(params['bedroom'])
  
  # select dates
  script = f&quot;document.getElementById('checkin').value ='{params['date_from']}';&quot;
  script += f&quot;document.getElementById('checkout').value ='{params['date_to']}';&quot;
  script +=  f&quot;document.getElementById('depart').value ='{params['date_from']}';&quot;
  script += f&quot;document.getElementById('arrivee').value ='{params['date_to']}';&quot;
  driver.execute_script(script)
  
  # submit form
  btn_rechercher = WebDriverWait(driver, 10).until(EC.element_to_be_clickable((By.XPATH, '//*[@id=&quot;boutonr&quot;]')))
  btn_rechercher.click()
      
  #----------   
  if (exists('plus_res')==&quot;true&quot;):
     
      btn_plus = WebDriverWait(driver, 10).until(EC.element_to_be_clickable((By.ID, 'plus_res')))
      btn_plus.click()
      sleep(10)
  else :
      pass
      
  urls = []    
  records = []
  hotels = WebDriverWait(driver, 10).until(EC.presence_of_all_elements_located((By.XPATH, &quot;//div[starts-with(@id,'produit_affair')]&quot;)))
  
  for hotel in hotels:
      link = hotel.find_element_by_xpath(&quot;.//span[@class='tittre_hotel']/a&quot;).get_attribute(&quot;href&quot;)
      urls.append(link)
  
  for url in urls:
      driver.get(url)
         
      def existsElement(xpath):
          try:
              driver.find_element_by_id(xpath);
          except NoSuchElementException:
              return &quot;false&quot;
          else:
              return &quot;true&quot;
     
      if (existsElement('result_par_arrangement')==&quot;false&quot;):
     
          btn_t = WebDriverWait(driver, 10).until(EC.element_to_be_clickable((By.XPATH, '//*[@id=&quot;moteur_rech&quot;]/form/div/div[3]/div')))
  
          btn_t.click()
          sleep(10)
      else :
          pass
                 
      
      try:
          name = str(WebDriverWait(driver, 10).until(EC.presence_of_element_located((By.XPATH, &quot;//div[@class='bloc_titre_hotels']/h2&quot;))).text)
          arropt = driver.find_element_by_xpath(&quot;//div[contains(@class,'line_result')][1]&quot;)
          opt = str(arropt.find_element_by_tag_name(&quot;b&quot;).text)
          num = len(arropt.find_elements_by_tag_name(&quot;option&quot;))
          optiondata = {}
          achats = {}
          marges= {}
          selection = Select(driver.find_element_by_id(&quot;arrangement&quot;))
  
          for i in range(num):
              try:
                  selection = Select(driver.find_element_by_id(&quot;arrangement&quot;))
                  selection.select_by_index(i)
                  time.sleep(2)
  
                  arr = driver.find_element_by_xpath(&quot;//select[@id='arrangement']/option[@selected='selected']&quot;).text
                  prize = driver.find_element_by_id(&quot;prix_total&quot;).text
  
                  optiondata[arr] = (int(prize))
  
                  btn_passe = WebDriverWait(driver, 10).until(EC.element_to_be_clickable((By.XPATH, '//*[@id=&quot;resultat&quot;]/div/form/div/div[2]/div[1]/div[2]/div[2]/div')))
                  btn_passe.click()
  
  
  
                  # params to select
                  params = {
                              'civilite_acheteur': 'Mlle',
                              'prenom_acheteur': 'test',
                              'nom_acheteur': 'test',
                              'e_mail_acheteur': 'test@gmail.com',
                              'portable_acheteur': '22222222',
                              'ville_acheteur': 'Test',
                          }
  
                  # select civilite
                  civilite_acheteur = Select(WebDriverWait(driver, 10).until(EC.element_to_be_clickable((By.NAME, 'civilite_acheteur'))))
                  civilite_acheteur.select_by_value(params['civilite_acheteur'])
  
                  # saisir prenom 
                  script  = f&quot;document.getElementsByName('prenom_acheteur')[0].value ='{params['prenom_acheteur']}';&quot;
                  script += f&quot;document.getElementsByName('nom_acheteur')[0].value ='{params['nom_acheteur']}';&quot;
                  script += f&quot;document.getElementsByName('e_mail_acheteur')[0].value ='{params['e_mail_acheteur']}';&quot;
                  script += f&quot;document.getElementsByName('portable_acheteur')[0].value ='{params['portable_acheteur']}';&quot;
                  script += f&quot;document.getElementsByName('ville_acheteur')[0].value ='{params['ville_acheteur']}';&quot;
                  driver.execute_script(script)
  
                  # submit form
                  btn_agence = driver.find_element_by_id('titre_Nabeul')
                  btn_agence.click()
  
                  btn_continuez = WebDriverWait(driver, 10).until(EC.element_to_be_clickable((By.ID, 'boutonr')))
                  btn_continuez.click()
  
                  achat = str(int(driver.find_element_by_xpath('/html/body/header/div[2]/div[1]/div[1]/div[4]/div[2]/div[2]').text.replace(' TND', '')))
  
                  achats[arr]=achat
  
                  marge =str(int(((float(prize) - float(achat)) / float(achat)) * 100))+&quot;%&quot;;
                  marges[arr]=marge
                  optiondata[arr]=prize,achat,marge
                  
                  
                  driver.get(url)
                  btn_display = WebDriverWait(driver, 10).until(EC.element_to_be_clickable((By.XPATH, '//*[@id=&quot;moteur_rech&quot;]/form/div/div[3]/div')))
  
                  btn_display.click()
                  sleep(10)
                 
  
              except StaleElementReferenceException:
                  pass
  
              
  
      except NoSuchElementException:
          pass
      
  
      s=&quot;{} : {} - {}&quot;.format(name, opt, optiondata)
      
  
      ds = []
  
      for l in s.splitlines():
              d = l.split(&quot;-&quot;)
  
              if len(d) &gt; 1:
                  df = pd.DataFrame(ast.literal_eval(d[1].strip()))
                  ds.append(df)
      for df in ds:
              df.reset_index(drop=True, inplace=True)
  
      df = pd.concat(ds, axis= 1)
  
      cols = df.columns
  
      cols = [((col.split('.')[0], col)) for col in df.columns]
  
      df.columns=pd.MultiIndex.from_tuples(cols)
  
      print(df.T)
      df.to_excel(&quot;v.xlsx&quot;)
  </code></pre>
  <p>it's displaying &quot;Palmyra club Nabeul Nabeul&quot; only
  How can i solve the probleme please this the final and most important part and thank you in advance.</p>
  <p><a href="https://i.stack.imgur.com/P7seA.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/P7seA.png" alt="enter image description here" /></a></p>