← 返回题库
初级

查询销售数据

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

示例

输入
print(solve())
期望输出
[('Laptop', 'North', 5, 1200), ('Phone', 'South', 10, 800), ('Laptop', 'East', 3, 1200), ('Tablet', 'West', 7, 500), ('Phone', 'North', 8, 800), ('Laptop', 'South', 2, 1200), ('Tablet', 'East', 15, 500), ('Phone', 'West', 12, 800), ('Laptop', 'North', 4, 1200), ('Tablet', 'South', 6, 500), ('Phone', 'East', 9, 800), ('Laptop', 'West', 3, 1200), ('Tablet', 'North', 11, 500), ('Phone', 'South', 5, 800), ('Laptop', 'East', 6, 1200), ('Tablet', 'West', 8, 500), ('Phone', 'North', 7, 800), ('Laptop', 'South', 4, 1200), ('Tablet', 'East', 10, 500), ('Phone', 'West', 6, 800)]
Python 代码 🔒 登录后使用
🔒

登录后即可练习

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