1

i have following code:

#import requests
from pandas import pandas as pd
base_url = "https://baden.liga.nu/cgi-bin/WebObjects/nuLigaTENDE.woa/wa/groupPage?championship=B2+S+2022&group="
Gruppe = ["1","24"] 
Team = ["H1","H2"] 

#Tabelle & Spielplan
for element in Gruppe:
    df = pd.read_html(base_url+str(element), index_col=0)
    for name in Team:
        df[0].to_csv('Exporte/Gruppe_'+str(element)+'_'+str(name)+'_Tabelle.csv', index = False)
        df[1].to_csv('Exporte/Gruppe_'+str(element)+'_'+str(name)+'_Spielplan.csv', index = False)

I only need the excel files generated for Gruppe "1"/ Team "H1" as well as Gruppe "2"/ Team "H2" but not for Gruppe "1"/ Team "H2" and not for Gruppe "2"/ Team "H1"

Anyone able to tell me how to setup the loop to get only the desired Excelfiles?

Thank you in advance.

Regards

1
  • @SalazarSlytherin if your columns are limited to 2-3, why do it in a loop? Commented Jun 30, 2022 at 7:12

1 Answer 1

1

You could use zip():

#import requests
from pandas import pandas as pd
base_url = "https://baden.liga.nu/cgi-bin/WebObjects/nuLigaTENDE.woa/wa/groupPage?championship=B2+S+2022&group="
Gruppe = ["1","24"] 
Team = ["H1","H2"] 

#Tabelle & Spielplan
for element,name in zip(Gruppe, Team):
    df = pd.read_html(base_url+str(element), index_col=0)
    df[0].to_csv('Exporte/Gruppe_'+str(element)+'_'+str(name)+'_Tabelle.csv', index = False)
    df[1].to_csv('Exporte/Gruppe_'+str(element)+'_'+str(name)+'_Spielplan.csv', index = False)

From the Python doc: zip iterates over several iterables in parallel, producing tuples with an item from each one.

An example from the doc:

for item in zip([1, 2, 3], ['sugar', 'spice', 'everything nice']):
    print(item)

>>> (1, 'sugar')
>>> (2, 'spice')
>>> (3, 'everything nice')
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.