数据分析_1-Jupyter的使用

数据分析

监控数据,发现异常,找出原因,提出建议,写分析报告

工具

Excel / SQL

BI工具---->PowerBI / Tableau / fineBI / 神策

Python+SQL

Python:

​ Numpy—>Numberical Python

​ Pandas—>Panel Data Set

​ Matplotlib

Jupyter Notebook - 数据科学

Jupyter Lab

数据思维和统计思维

数据分析方法论

Jupyter

显示行号:蓝色(命令模式),l/L

Ctrl+Enter 光标在当前

Alt+Enter

Shift+Enter光标往下跳

命令模式快捷键:

​ l/L:添加或去掉行号

​ Ctrl+Enter:运行代码,留在当前单元格

​ Shift+Enter:运行代码,移到下一个单元格

​ Alt+Enter:运行代码,在下方新增一个单元格

​ A:在上方添加单元格

​ B:在下方加单元格

​ DD:删除当前单元格

​ h:查看快捷键的帮助

NP和PD

import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
import random
names=('一一','二二','三三','四四','五五')
scores=[[random.randrange(60,101) for j in range(3) ]for i in range(5)]
for i,name in enumerate(names):
    print(f'{name}:{sum(scores[i])/3:.2f}')
for i,course in enumerate(courses):
    tmp = [scores[j][i]for j in range(5)]
    print(f'{course}高:{max(tmp)},低:{min(tmp)}')
scores=np.array(scores)
type(scores)
# numpy.ndarray

求平均值mean,round:小数位数

np.round(scores.mean(axis=1),1)
# array([71.3, 74.7, 98.7, 81.7, 66.7])

求每科最大值

scores.max(axis=0)
# array([98, 99, 99])
np.max(scores,axis=0)
# array([98, 99, 99])
scores.min(axis=0)
# array([61, 71, 60])
np.min(scores,axis=0)
# array([61, 71, 60])

Pandas—>PanelDataSet—>DataFrame

df = pd.DataFrame(data=scores,columns=courses,index=names)
#index:行索引
df
#	语	数	外
#一一	77	89	71
#二二	78	81	73
#三三	82	80	97
#四四	66	73	94
#五五	89	73	100
# 沿1轴计算平均分,再将平均分加入表格
df['平均分']=np.round(df.mean(axis=1),2)
df
#	语	数	外	平均分
#一一	77	89	71	79.00
#二二	78	81	73	77.33
#三三	82	80	97	86.33
#四四	66	73	94	77.67
#五五	89	73	100	87.33

max_scores = df.max()
min_scores = df.min()
df.loc['最高分']=max_scores
#loc:取行
df.loc['最低分']=min_scores
df
#	语	数	外	平均分
#一一	77.0	89.0	71.0	79.00
#二二	78.0	81.0	73.0	77.33
#三三	82.0	80.0	97.0	86.33
#四四	66.0	73.0	94.0	77.67
#五五	89.0	73.0	100.0	87.33
#最高分	89.0	89.0	100.0	87.33
#最低分	66.0	73.0	71.0	77.33

导出xlsx

!pip install -U openpyxl xlrd xlwt
# 引入包
df.to_excel('学生成绩表.xlsx')

忽略所有警告的方法

import warning
#忽略所有的警告信息
warnings.filterwarnings('ignore')

查看当前工作路径

%pwd
# %是魔法方法
#'C:\\Users\\Administrator\\Desktop\\DataAnalysis2103'

查看路径下有啥玩意

%ls

给图设置参数

plt.rcParams['font.sans-serif']=['STFangsong','STZhongsong']
plt.rcParams['axes.unicode_minus']=False

dpi---->dot per inch
svg---->矢量图

设置图片设置

%config InlineBackend.figure_format='svg'

显示和保存图片

df.plot(figsize=(5,3),kind='bar',y=['语','数','外'])
# 定制x轴的刻度
plt.xticks(rotation=0)
# 定制图例的位置
plt.legend(loc='lower right')
# 保存图片
plt.savefig('dome.svg')
# 显示图片
plt.show()
# 在图片显示的时候会释放,所以一定要先保存再显示
df.plot?
#    The kind of plot to produce:
#
#    - 'line' : line plot (default)
#    - 'bar' : vertical bar plot
#    - 'barh' : horizontal bar plot
#    - 'hist' : histogram
#    - 'box' : boxplot
#    - 'kde' : Kernel Density Estimation plot
#    - 'density' : same as 'kde'
#    - 'area' : area plot
#    - 'pie' : pie plot
#    - 'scatter' : scatter plot
#    - 'hexbin' : hexbin plot.
# 创建画布
plt.figure(figsize=(8,3),dpi=125)
# 创建坐标系
# 指定坐标轴
x = np.linspace(-2*np.pi,2*np.pi,100)   # 等差数列
y = np.sin(x)
plt.plot(x,y)

#输出一个正弦图
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值