
上QQ阅读APP看书,第一时间看更新
3.1.3 常用数据库数据
1.读取MySQL数据库数据
Python可以直接读取MySQL数据库,连接之前需要安装pymysql库。例如,统计汇总数据库orders表中2020年不同类型商品的销售额和利润额,示例代码如下:

在JupyterLab中运行上述代码,输出结果如下:

2.读取SQL Server数据库数据
Python可以直接读取SQL Server数据库数据,连接之前需要安装pymssql库。例如,查询数据库orders表中2020年利润额在400元以上的所有订单,示例代码如下:

在JupyterLab中运行上述代码,输出如下:
