本课程共七个章节,课程地址:7周成为数据分析师(完结)_哔哩哔哩_bilibili
- 数据分析思维
- 业务知识
- Excel
- 数据可视化
- SQL
- 统计学
- Python
- Python的数据科学环境(P86)
- Python基础(P87-P97)
- 数据分析常用包:Numpy和Pandas(P98-P112)
- Python连接数据库(P113-P114)
- 数据分析案例(P115-P124)
- 数据可视化:Matplotlib和Seaborn(P125-P138)
- 数据分析平台:superset(P139-P143)
目录
第七周:Python(P86-P143)
七、数据分析平台:superset(P139-P143)
(一)superset安装
(二)superset使用
- 激活步骤
- 加载数据库
- SQL编辑器
- 切片绘图
用 Python 搭建 BI:superset(包括SQL语句、可视化等)
(一)superset安装cmd 里操作:
- 开辟虚拟环境,专门用来安装superset:
conda create -n 环境名 python=版本
conda create -n superset python=3.6 # 建议用python 3.6!我用其他版本一直不成功
- 激活虚拟环境:
activate superset
- 安装:
# 虚拟环境下安装superset
pip install superset --trusted-host pypi.tuna.tsinghua.edu.cn
推荐网站:https://www.lfd.uci.edu/~gohlke/pythonlibs/ 下载python包的依赖环境
- cp34:python3.4
- 电脑一般都是amd64
下载好后,在cmd里先输入pip install,再将下载好的包拖拽进cmd,会自动附上路径
- 启动superset:
安装位置:d:\anaconda\envs\superset\lib\site-packages\superset
在这个路径下输入:
python superset
会报大量的 No Module called xxx 之类的错误,解决思路:缺什么补什么
其中比较特殊的两个问题:
# ModuleNotFoundError: No module named 'geohash'
解决方法:
1、pip install之后,还要将Geohash文件夹改成geohash(大写G改为小写g);
2、将文件夹下的 __init__.py 中的 from geohash 改成 from .geohash
(注意:在geohash前面多了一个点)
# ImportError: cannot import name 'RowProxy'
解决办法:
pip install sqlalchemy==1.3.23 -i http://mirrors.aliyun.com/pypi/simple/ --trusted-host mirrors.aliyun.com
直到输入 python superset 后出现以下界面,说明OK:
- 创建管理员账号:
在创建管理员账号时报:AttributeError: 'NoneType' object has no attribute 'auth_type'
解决方案:①、先执行:python superset init ②、再执行 python superset fab create-admin
出现这两行绿色的字说明OK了
- 更新superset中自带的数据库:
python superset db upgrade
python superset init
python superset run -p 8088
在浏览器中输入上面那个网址 http://127.0.0.1:8088/,进入界面,如下:
Username就是admin,Password就是上面自己设置的那个密码
安装过程中参考的一些帖子:
Superset 两种安装方式详解_与光同尘~追光者的博客-CSDN博客
python3安装superset踩坑解决过程_南叔先生的博客-CSDN博客
Windows Superset 填坑记_redfox1985的博客-CSDN博客
superset云主机上出现报错_微电子学与固体电子学-俞驰的博客-CSDN博客
(二)superset使用(1)激活步骤:
activate superset
D:
cd d:\anaconda\envs\superset\lib\site-packages\superset\bin
python superset init
python superset run -p 8088
可以点击这里切换成中文(部分):
1. 用户权限
- 用户列表里可以创建新用户,若想部署到服务器上,可以添加一些成员来使用,并给其配置相应权限
- 角色列表里可以看到不同角色权限的解读
2. Manage(管理):与样式相关
3. Sources(数据源):
4. Charts(切片):单图即叫切片
5. Dashboards(看板):很多切片组成一个看板
6. SQL Lab(SQL工具箱):SQL编辑器
编辑SQL时出现以下问题:
解决:python superset 中的SQL Editor 出现{e}怎么办_心际花园的博客-CSDN博客
(2)加载数据库:Sources ——> Databases ——> 添加新记录
SQLAlchemy URI 为 mysql+pymysql://root:root@localhost:3306/data?charset=utf8
报错原因:没有安装pymysql,在superset环境里安装即可
最后保存即可
(3)SQL编辑器:
- 数据预览:
- 输入Query
SELECT city,positionId,education,salary from data.dataanalyst as d
left join data.company as c on d.companyId = c.companyId
where city='深圳'
and salary like '%%1%%' # 薪资里带数字1的
模糊查询:两边都是%%(注意是两个百分号)
...
where education like '%%本%%'
(4)切片绘图:
SELECT city,positionId,education,salary from data.dataanalyst as d
left join data.company as c on d.companyId = c.companyId