You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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
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
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'")
The text was updated successfully, but these errors were encountered: