Use our APIs for data analysis (Jupyter/Python)

Learn how to leverage APIs within Jupyter Notebooks using the pandas library and existing workforce data. Combine your data with trending skills obtained from the Occupations API to gain valuable insights.

Jupyter Notebooks provide an interactive environment for data analysis and exploration. This page will guide you on how to leverage our APIs within Jupyter Notebooks using the pandas library and existing workforce data. We'll combine the data from your workforce.csv file with the data obtained from our APIs, specifically the Occupations API to retrieve trending skills for each occupation.

Prerequisites

Before getting started, ensure that you have the following:

  1. Jupyter Notebook installed
  2. pandas library installed (pip install pandas)
  3. Access to the Occupations API and an API key

Importing the Required Libraries

First, import the necessary libraries, including pandas and requests, in your Jupyter Notebook:

import pandas as pd
import requests

Loading and Preparing the Workforce Data

Load your workforce data from the CSV file using pandas:

# Load the workforce data from CSV
data = pd.read_csv('workforce.csv')

# Display the first few rows to verify the data
data.head()

Ensure that the CSV file is in the correct format and that the data is correctly loaded into the pandas DataFrame.

Making API Requests and Extracting Trending Skills

Now, let's make API requests to retrieve the trending skills for each occupation in your workforce data:

# Define the base API URL
base_url = 'https://example.com/di/v1/occupations/'

# Iterate through each row in the workforce data
for index, row in data.iterrows():
    occupation_id = row['occupation_id']
    country_code = row['country_code']
    
    # Construct the API URL
    api_url = f'{base_url}{occupation_id}/skills/trending?country_code={country_code}'
    
    # Send the API request
    response = requests.get(api_url, headers={'Authorization': 'Bearer YOUR_API_KEY'})
    
    # Check the response status code
    if response.status_code == 200:
        # Retrieve the trending skills from the response
        trending_skills = response.json()
        
        # Extract the skill names from the trending skills
        skill_names = [skill['name'] for skill in trending_skills]
        
        # Add the skill names to the workforce data
        data.at[index, 'trending_skills'] = ', '.join(skill_names)
    else:
        # Handle API request errors
        print(f'API request failed for occupation ID {occupation_id}')

In this code snippet, we're iterating through each row in the workforce data and sending API requests to retrieve the trending skills for the corresponding occupation and country. We extract the skill names from the API response and add them to a new column called 'trending_skills' in the workforce data DataFrame.

Analyzing and Visualizing the Data

With the trending skills data added to the workforce data DataFrame, you can now analyze and visualize the data as desired using the pandas and matplotlib libraries:

# Perform data analysis and visualization
# ...

# Example: Count the occurrences of each trending skill
skill_counts = data['trending_skills'].str.split(', ').explode().value_counts()

# Example: Create a bar plot of the skill counts
skill_counts.plot(kind='bar', figsize=(10, 6), title='Trending Skills')

Feel free to perform further analysis, create visualizations, or combine the data with other datasets to gain valuable insights into your workforce trends and skill requirements.

Remember to refer to our API documentation for specific endpoints, headers, and authentication requirements. If you encounter any issues or have questions, don't hesitate to reach out to our support team. Happy analyzing!