how to export a python code into csv file

377 Views Asked by At

I have a really simple question I want to export the output for this code into csv file, what should I add as it shows the result printed to the terminal (json) and I want the results to be csv files


import requests
import pandas as pd
import numpy as np
import json

payload = {}
headers = {}

CLIENT_ID = "****"
CLIENT_SECRET = "****"
TOKEN = "****"


ll1 = "18.036442,42.492103"
ll2 = "18.036808,42.117917"
ll3 = "18.458814,42.485903"
ll4 = "18.453989,42.115408"


def make_request(payload, headers, ll1, CLIENT_ID,CLIENT_SECRET ):
   url = f"https://api.foursquare.com/v2/venues/search" \
   "?client_id={CLIENT_ID}" \
   "&client_secret={CLIENT_SECRECT}" \
   "&token={TOKEN}" \
   "&ll={ll1}" \
   "&intent=browse&radius=10000&v=20210927"

   response = requests.request("GET", url, headers=headers, data=payload)
   return response.json()


data = make_request(payload, headers, ll1,CLIENT_ID, CLIENT_SECRET)
data = make_request(payload, headers, ll2,CLIENT_ID, CLIENT_SECRET)
data = make_request(payload, headers, ll3,CLIENT_ID, CLIENT_SECRET)
data = make_request(payload, headers, ll4,CLIENT_ID, CLIENT_SECRET)


response_api = requests.get(
   data
)

print (data)

data = response_api.json()

Thank you!

1

There are 1 best solutions below

0
cvsrt On

You can use this site. or you can use this code:

json_file = {'name':["aparna", "pankaj", "sudhir", "Geeku"],'degree': ["MBA", "BCA", "M.Tech", "MBA"],'score':[90, 40, 80, 98]}
df = pd.DataFrame(json_file).to_excel("excel.xlsx")