Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

US higher education data dump with executive details, private public, 2 or 4 year, state, region, location. #14

Open
Jennbrown281 opened this issue Sep 20, 2024 · 0 comments

Comments

@Jennbrown281
Copy link

import requests
import pandas as pd

URL to the IPEDS API for institutions

url = "https://api.data.gov/ed/collegescorecard/v1/schools.json"

Parameters for the API request

params = {
'api_key': 'YOUR_API_KEY', # Replace with your API key
'fields': 'id,school.name,school.state,school.locale,school.control,latest.enrollment.full_time,latest.enrollment.total,latest.programs.cip_4_digit',
'per_page': 100
}

Function to fetch data

def fetch_data(url, params):
response = requests.get(url, params=params)
response.raise_for_status()
return response.json()

Fetch and process data

def get_institutions():
institutions = []
page = 0

while True:
    params['page'] = page
    data = fetch_data(url, params)
    institutions.extend(data['results'])
    
    # Break if there are no more results
    if len(data['results']) < params['per_page']:
        break
    
    page += 1

return institutions

Convert data to DataFrame and save as CSV

def save_to_csv(data):
df = pd.DataFrame(data)
df.to_csv('us_higher_education_institutions.csv', index=False)

if name == "main":
institutions = get_institutions()
save_to_csv(institutions)
print("Data saved to 'us_higher_education_institutions.csv'")

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant