初级
建立银行数据库并查询所有账户
未完成
初级参考
完整示例代码供参考,建议自己理解后重新输入
def solve():
from pyodide.http import open_url
customers_csv = open_url("https://data.zuihe.com/dbd/banking/state_B00/customers.csv").read()
accounts_csv = open_url("https://data.zuihe.com/dbd/banking/state_B00/accounts.csv").read()
cards_csv = open_url("https://data.zuihe.com/dbd/banking/state_B00/cards.csv").read()
import sqlite3
import pandas as pd
from io import StringIO
conn = sqlite3.connect(':memory:')
pd.read_csv(StringIO(customers_csv)).to_sql('customers', conn, index=False, if_exists='replace')
pd.read_csv(StringIO(accounts_csv)).to_sql('accounts', conn, index=False, if_exists='replace')
result = pd.read_sql_query("""
SELECT c.name, a.account_no, a.type, a.balance
FROM accounts a
JOIN customers c ON a.customer_id = c.id
ORDER BY a.balance DESC
""", conn)
print(result.to_string(index=False))
conn.close()
示例
输入
solve()
期望输出
name account_no type balance 刘洋 6217001000000010 wealth 1200000.0 李芳 6217001000000004 wealth 500000.0 刘洋 6217001000000009 savings 256000.0 李芳 6217001000000003 savings 128500.0 陈霞 6217001000000006 savings 88000.0 周浩 6217001000000012 savings 42000.0 张伟 6217001000000001 savings 15230.5 孙梅 6217001000000011 savings 9800.0 王军 6217001000000005 savings 3200.0 赵磊 6217001000000008 savings 450.0 张伟 6217001000000002 credit 0.0 陈霞 6217001000000007 credit 0.0
👑
升级 VIP
解锁全部题目,畅通无阻地学习
- ✓ 解锁全部训练包所有题目
- ✓ 查看完整参考代码和提示
- ✓ 浏览器内直接运行 Python 代码
- ✓ 自动批改 + 进度追踪
30天
¥18
1年
¥99
2年
¥158
3年
¥199