Jupyter - Code doesn't concatenate data

Multi tool use
Multi tool use


Jupyter - Code doesn't concatenate data



I have been trying to scrape statistics from several football matches, from the website "www.meusresultados.com" , The scrape is working fine, but it is not concatenating the data into a single dataframe
For example, I scrape 5 different matches, and the resulting dataframe show the first match 5 times.
Inside "gg" there are several url's that the selenium webdriver uses to scrape data from.
My objective is to create a dataframe where each row represents a different game, but at the moment it is only showing the first game.


import numpy as np
import time
import pandas as pd
from pandas.io.html import read_html
from pandas import DataFrame
from selenium import webdriver
import string
import random
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
driver = webdriver.Chrome()
driver.implicitly_wait(1)
wait = WebDriverWait(driver, 1)

summary_stats = DataFrame()

stats =
import pandas as pd
for url in gg[:6]:
driver.get(url)
for k in driver.find_elements_by_xpath('//div[@class="team-primary-content"]'):
for i in driver.find_elements_by_xpath('//div[@id="tab-statistics-0-statistic"]'):
stats.append(k.text+"n"+i.text)
l = stats[0].split('n')
x = ([s.replace('-','') for s in l])
columns = ['Equipa da casa','Equipa visitante',
'Posse de bola[C]', 'Posse de bola[V]',
'Tentativas de golo[C]', 'Tentativas de golo[V]',
'Remates à baliza[C]', 'Remates à baliza[V]',
'Remates fora[C]', 'Remates fora[V]',
'Remates Bloqueados[C]','Remates Bloqueados[V]',
'Livres[C]','Livres[V]',
'Cantos[C]','Cantos[V]',
'Foras de Jogo[C]','Foras de Jogo[V]',
'Lançamentos[C]','Lançamentos[V]',
'Defesas de guarda-redes[C]','Defesas de guarda-redes[V]',
'Faltas[C]','Faltas[V]',
'Cartões amarelos[C]','Cartões amarelos[V]',
'Cartões vermelhos[C]','Cartões vermelhos[V]',
'Total de passes[C]','Total de passes[V]',
'Passes completos[C]','Passes completos[V]',
'Cortes[C]','Cortes[V]',
'Golos de casa','Golos de fora']
df99 = pd.DataFrame({
'Equipa da casa': [x[0]], #Equipa
'Equipa visitante': [x[5]],
'Posse de bola[C]': [x[x.index('Posse de bola')-1] if 'Posse de bola' in x else float('NaN')],
'Posse de bola[V]': [x[x.index('Posse de bola')+1] if 'Posse de bola' in x else float('NaN')],
'Tentativas de golo[C]':[x[x.index('Tentativas de golo')-1] if 'Tentativas de golo' in x else float('NaN')],
'Tentativas de golo[V]':[x[x.index('Tentativas de golo')+1] if 'Tentativas de golo' in x else float('NaN')],
'Remates à baliza[C]': [x[x.index('Remates à baliza')-1] if 'Remates à baliza' in x else float('NaN')],
'Remates à baliza[V]': [x[x.index('Remates à baliza')+1] if 'Remates à baliza' in x else float('NaN')],
'Remates fora[C]': [x[x.index('Remates fora')-1] if 'Remates fora' in x else float('NaN')],
'Remates fora[V]':[x[x.index('Remates fora')+1] if 'Remates fora' in x else float('NaN')], # Remates fora
'Remates Bloqueados[C]': [x[x.index('Remates Bloqueados')-1] if 'Remates Bloqueados' in x else float('NaN')],
'Remates Bloqueados[V]': [x[x.index('Remates Bloqueados')+1] if 'Remates Bloqueados' in x else float('NaN')], #Remates bloqeuados
'Livres[C]': [x[x.index('Livres')-1] if 'Livres' in x else float('NaN')],
'Livres[V]': [x[x.index('Livres')+1] if 'Livres' in x else float('NaN')], #Livres
'Cantos[C]': [x[x.index('Cantos')-1] if 'Cantos' in x else float('NaN')],
'Cantos[V]':[x[x.index('Cantos')+1] if 'Cantos' in x else float('NaN')], #Cantos
'Foras de Jogo[C]': [x[x.index('Foras de Jogo')-1] if 'Foras de Jogo' in x else float('NaN')],
'Foras de jogo[V]': [x[x.index('Foras de Jogo')+1] if 'Foras de Jogo' in x else float('NaN')], #Foras de jogo
'Lançamentos[C]': [x[x.index('Lançamentos')-1] if 'Lançamentos' in x else float('NaN')],
'Lançamentos[V]': [x[x.index('Lançamentos')+1] if 'Lançamentos' in x else float('NaN')], # Lançamentos
'Defesas de guarda-redes[C]': [x[x.index('Defesas de guardaredes')-1] if 'Defesas de guardaredes' in x else float('NaN')],
'Defesas de guarda-redes[V]': [x[x.index('Defesas de guardaredes')+1] if 'Defesas de guardaredes' in x else float('NaN')], #Defesas
'Faltas[C]': [x[x.index('Faltas')-1] if 'Faltas' in x else float('NaN')],
'Faltas[V]': [x[x.index('Faltas')+1] if 'Faltas' in x else float('NaN')] , #Faltas
'Cartões amarelos[C]':[x[x.index('Cartões amarelos')-1] if 'Cartões amarelos' in x else float('NaN')],
'Cartões amarelos[V]':[x[x.index('Cartões amarelos')+1] if 'Cartões amarelos' in x else float('NaN')], #cartoes amarelos
'Cartões vermelhos[C]': [x[x.index('Cartões vermelhos')-1] if 'Cartões vermelhos' in x else float('NaN')],
'Cartões vermelhos[V]': [x[x.index('Cartões vermelhos')+1] if 'Cartões vermelhos' in x else float('NaN')], #cartoes vermelhos
'Total de passes[C]': [x[x.index('Total de passes')-1] if 'Total de passes' in x else float('NaN')],
'Total de passes[V]': [x[x.index('Total de passes')+1] if 'Total de passes' in x else float('NaN')], #total de passe
'Passes completos[C]': [x[x.index('Passes completos')-1] if 'Passes completos' in x else float('NaN')],
'Passes completos[V]': [x[x.index('Passes completos')+1] if 'Passes completos' in x else float('NaN')], #passes completo
'Cortes[C]': [x[x.index( 'Cortes')-1] if 'Cortes' in x else float('NaN')],
'Cortes[V]':[x[x.index( 'Cortes')+1] if 'Cortes' in x else float('NaN')], # Cortes
'Golos de casa':[x[1]],
'Golos de fora':[x[2]]},
dtype=np.int32,columns=columns)
summary_stats = pd.concat([summary_stats,df99],ignore_index=True)
driver.close()









By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

jaE5CDwJH,F,WquNn8n1z,q94nwp bQ,b35f6,g5oEDO,YnXARiGD9ZV5LtOZdiZ3Wy pFTCgJjdseRxd 0uG
UIU8 KG0AOsynUwmSWjamPyFFdTr5TLA,kfd,4voQxnjTCE3agc8ZFBNbeL55PbJPbu,04Nw6xz4,MMk,k

Popular posts from this blog

PHP contact form sending but not receiving emails

Do graphics cards have individual ID by which single devices can be distinguished?

Create weekly swift ios local notifications