初级
查询学员的报名课程列表
未完成
初级参考
完整示例代码供参考,建议自己理解后重新输入
def solve():
from pyodide.http import open_url
instructors_csv = open_url("https://data.zuihe.com/dbd/education/state_D01/instructors.csv").read()
courses_csv = open_url("https://data.zuihe.com/dbd/education/state_D01/courses.csv").read()
students_csv = open_url("https://data.zuihe.com/dbd/education/state_D01/students.csv").read()
enrollments_csv = open_url("https://data.zuihe.com/dbd/education/state_D01/enrollments.csv").read()
assignments_csv = open_url("https://data.zuihe.com/dbd/education/state_D01/assignments.csv").read()
submissions_csv = open_url("https://data.zuihe.com/dbd/education/state_D01/submissions.csv").read()
import sqlite3
import pandas as pd
from io import StringIO
conn = sqlite3.connect(':memory:')
pd.read_csv(StringIO(enrollments_csv)).to_sql('enrollments', conn, index=False, if_exists='replace')
pd.read_csv(StringIO(courses_csv)).to_sql('courses', conn, index=False, if_exists='replace')
result = pd.read_sql_query("""
SELECT c.title, e.progress, e.enrolled_at, e.completed_at
FROM enrollments e
JOIN courses c ON e.course_id = c.id
WHERE e.student_id = 1
ORDER BY e.enrolled_at
""", conn)
print(result.to_string(index=False))
conn.close()
示例
输入
solve()
期望输出
title progress enrolled_at completed_at
Python从零到精通 100 2025-01-06 10:00:00 2025-02-10 18:00:00
算法与数据结构 65 2025-01-20 09:00:00 None
SQL数据库实战 100 2025-02-01 08:00:00 2025-03-05 20:00:00
Python数据分析实战 70 2025-03-01 09:00:00 None
👑
升级 VIP
解锁全部题目,畅通无阻地学习
- ✓ 解锁全部训练包所有题目
- ✓ 查看完整参考代码和提示
- ✓ 浏览器内直接运行 Python 代码
- ✓ 自动批改 + 进度追踪
30天
¥18
1年
¥99
2年
¥158
3年
¥199