18-数据分析python——pandas——连接mysql数据库

本章内容包括:



//input1
import pymysql
import pandas as pd
from sqlalchemy import create_engine
sql = 'select * from company'
engine = create_engine('mysql+pymysql://kuku:mysql1219@localhost:3306/data')
df = pd.read_sql(sql,engine)
df.head()



//output1
companyId   companyFullName companyLabelList    companyShortName    companySize businessZones
0   43  北京欧应科技有限公司  ['五险一金', '扁平化管理', '创业型企业', '岗位晋升']  唯医网 150-500人    ['东大桥', 'CBD', '朝外']
1   53  北京创锐文化传媒有限公司    ['技能培训', '节日礼物', '季度奖金', '岗位晋升']    聚美优品    2000人以上 ['东直门', '海运仓', '东四']
2   62  北京字节跳动科技有限公司    ['扁平管理', '弹性工作', '大厨定制三餐', '就近租房补贴']    今日头条    2000人以上 ['双榆树', '大钟寺', '中关村']
3   70  宝宝树(北京)信息技术有限公司 ['商业医疗保险', '股票期权', '带薪年假', '扁平管理']  宝宝树 500-2000人   ['团结湖', '朝阳公园', '三里屯']
4   91  高德软件有限公司    ['弹性工作', '帅哥多', '美女多', '五险一金']  阿里巴巴移动事业群-高德    2000人以上 ['城南']







备注:

18-数据分析python——pandas——连接mysql数据库_第1张图片
注意匹配

18-数据分析python——pandas——连接mysql数据库_第2张图片
注意匹配

在安装之前,注意电脑安装pymysql,如没有安装,请参考下面的教程(anaconda没有)
打开cmd窗口,直接输入。

//input1
C:\Users\ZHAO Yue>pip install pymysql




//output1
Collecting pymysql
  Retrying (Retry(total=4, connect=None, read=None, redirect=None, status=None)) after connection broken by 'ReadTimeoutError("HTTPSConnectionPool(host='pypi.org', port=443): Read timed out. (read timeout=15)")': /simple/pymysql/
  Downloading https://files.pythonhosted.org/packages/ed/39/15045ae46f2a123019aa968dfcba0396c161c20f855f11dea6796bcaae95/PyMySQL-0.9.3-py2.py3-none-any.whl (47kB)
    100% |████████████████████████████████| 51kB 3.0kB/s
twisted 18.7.0 requires PyHamcrest>=1.9.0, which is not installed.
mysql-connector-python 8.0.13 requires protobuf>=3.0.0, which is not installed.
Installing collected packages: pymysql
Successfully installed pymysql-0.9.3
You are using pip version 10.0.1, however version 19.0.3 is available.
You should consider upgrading via the 'python -m pip install --upgrade pip' command.








//input2
C:\Users\ZHAO Yue>python -m pip install --upgrade pip //看到的我pip不是最新版,我就更新了一下pip,但是只有小飞机打开全局模式,才可以下载新版pip。




//output2
Collecting pip
  Downloading https://files.pythonhosted.org/packages/d8/f3/413bab4ff08e1fc4828dfc59996d721917df8e8583ea85385d51125dceff/pip-19.0.3-py2.py3-none-any.whl (1.4MB)
    100% |████████████████████████████████| 1.4MB 117kB/s
twisted 18.7.0 requires PyHamcrest>=1.9.0, which is not installed.
mysql-connector-python 8.0.13 requires protobuf>=3.0.0, which is not installed.
Installing collected packages: pip
  Found existing installation: pip 10.0.1
    Uninstalling pip-10.0.1:
      Successfully uninstalled pip-10.0.1
Successfully installed pip-19.0.3

你可能感兴趣的:(18-数据分析python——pandas——连接mysql数据库)