[Python] How do you use pandas read_csv() method if the csv is stored as a variable?

Discussão em 'Python' iniciado por Stack, Abril 28, 2025.

  1. Stack

    Stack Membro Participativo

    I'm trying to work with data in a google spreadsheet, reading it into a csv and then working with it as a dataframe using pandas.read_csv().

    I can get the csv read out into a variable (the variable "data" below), but cannot then use pandas.read_csv() on the variable. I've tried casting it as a string, using os.cwd(), etc.

    r = requests.get('I put my google sheets url here')
    data = r.text
    print(data)

    #csv is printed out properly

    df = pd.read_csv(filepath_or_buffer = data, header = 1, usecols = ["Latitude", "Longitude"])
    print(df)


    No matter what I try, I always get a FileNotFoundException.

    I'm a python newbie, so I'm probably missing something something really obvious. Thank you!

    Continue reading...

Compartilhe esta Página