The purpose of this project is to get data using api.
This is my first project using api to get data
I did this project with guidance from 365 Data Science
Link to the API Documentation I used Job Search API
Importing Necessary Libraries
import requests
import json
url = "https://jsearch.p.rapidapi.com/search"
querystring = {"query":"Data Analyst in Lagos, Nigeria","num_pages":"1"}
headers = {
"X-RapidAPI-Key": "374e7caff4mshbdf0dc9feaf2c44p1807dfjsn55b29ff65a00",
"X-RapidAPI-Host": "jsearch.p.rapidapi.com"
}
response = requests.request("GET", url, headers=headers, params=querystring)
respond = response.json()
# View the API result
print(json.dumps(respond, indent = 4))
# View the api keys
respond.keys()
Output
dict_keys(['status', 'request_id', 'data'])
# View the data key result
print(json.dumps(respond['data'][0], indent=4))
# View the request_id key
respond["request_id"]
Output
'3702f9d9-3f27-4d12-9224-6040141d9d83'
Turning data into tabular form with pandas with the api collection key (data)
import pandas
df = pd.DataFrame(respond['data'])
df
# Optional
# Remove the unecessary columns
data = df.drop(columns = ["job_description", "employer_logo","employer_website", "job_id",
"job_posted_at_timestamp", "job_posted_at_datetime_utc", "job_latitude",
"job_longitude", "job_google_link","job_offer_expiration_datetime_utc","job_experience_in_place_of_education",
"job_min_salary", "job_max_salary","job_salary_currency",
"job_salary_period", "job_highlights", "job_benefits"], inplace = True)
Transforming and saving data into a csv file format
df.to_csv (r'data.csv', encoding = 'utf-8', index = None)
job = pd.read_csv('data.csv')
job.head()
# Check the data info
job.info()
You should see your saved csv format in the file path you saved it into
Top comments (0)