[Python] Read in list of urls from file then use pandas to make changes and output new csv file

Discussão em 'Python' iniciado por Stack, Maio 24, 2025.

  1. Stack

    Stack Membro Participativo

    I have this script that read in a list of csv's from a text file, the files are hosted online. The script then makes changes to each of the files and creates a new csv from the changes. At the moment it works for a single file by I cant get it to run through all the links and make new csvs files from each.

    import pandas as pd

    f = open( "urls.txt", "r" )
    lines = []
    url = lines
    for line in f:
    lines.append(line)
    df = pd.read_csv(url,skiprows=7)
    df = df.rename(columns={'*.conradbrothers.com/*_20180501':'Ranking','*.conradbrothers.com/*_difference': 'Difference'}) # Rename the top column names
    df = df.replace(to_replace=["-"],value="0") #find - and replace with 0
    print(df)
    df.to_csv('seo.csv',index=False) #output file as a csv
    print(line)

    f.close()

    Continue reading...

Compartilhe esta Página