← 返回题库
初级

查询最早的5部电影

未完成
初级参考 完整示例代码供参考,建议自己理解后重新输入
def solve():
    import sqlite3
    import pandas as pd
    conn = sqlite3.connect(':memory:')
    df = pd.read_csv('https://liangdaima.com/static/data/ds_movies.csv')
    df.to_sql('movies', conn, index=False)
    result = conn.execute('SELECT title, year FROM movies ORDER BY year ASC LIMIT 5').fetchall()
    conn.close()
    return result

示例

输入
print(solve())
期望输出
[('The Godfather', 1972), ('The Silence of the Lambs', 1991), ('The Shawshank Redemption', 1994), ('Pulp Fiction', 1994), ('Forrest Gump', 1994)]
Python 代码 🔒 登录后使用
🔒

登录后即可练习

注册免费账号,在浏览器中直接运行 Python 代码