Looping no request

Asked

Viewed 43 times

-1

How could I make a looping to bring information from the request of a csv coordinate list and take the result to another csv?

import requests
import pandas as pd

parametro = dict(latitude=-23.512294, longitude=-46.667259, status=1, lista=1, limite=96, acessibilidade='')

r = requests.post('https://www.banco24horas.com.br/index/busca-json-terminal', data=parametro)

df = r.json()
display(df)
  • Look - telling how to write a CSV from the thick of this data is relatively easy - but if you (or you) have any other programming needs out there, I suggest studying the Python language more systematically for a few days

1 answer

0

The value returned after the request is not a "CSV" - (Csvs is a generic name for a file type, nor is it a data format that exists in memory).

Anyway, once you are already using Pandas, write a CSV file from the key detalhes of that answer is trivial. (The answer does not just return a list with information about Atms, there are other fields as well):

import requests
import pandas as pd

parametro = dict(latitude=-23.512294, longitude=-46.667259, status=1, lista=1, limite=96, acessibilidade='')

r = requests.post('https://www.banco24horas.com.br/index/busca-json-terminal', data=parametro)

df = pd.DataFrame(r.json()['detalhes']
df.to_csv('meu_arquivo.csv')

The flame .to_csv of Pandas already creates the file and writes all data serialized in the correct way.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.