利用python进行数据分析
课程相关说明
学习Python数据分析的理由
- 免费,开源,简单,易学
- 开源库资源丰富,numpy,pandas,scipy等库有机结合可以完全替代matlab的功能
- Python可以配合C++混合编程,提供更加高效的计算效率
适用人群
- 具有一定的Python编程基础
- 对利用python进行数据分析具有浓烈兴趣
- 面对第三方压力,必须使用python进行数据分析
软件要求
- 安装PyCharm,Anaconda(4.3.1)
- python解释器版本-version3.6.0
- 安装课件代码中依赖的第三方包或模块
序号 | 库(模块)名称 | 说明 |
---|
1 | Numpy | Python数学库 |
2 | Pandas | Python数据分析库(Python Anaylise Data) |
3 | Matplotlib | Python绘图库 |
4 | Json | Json格式数据处理模块 |
5 | Xml | XML个数数据处理模块 |
Python基础语法回顾
变量
python是一种动态弱类型语言,变量在使用的时候即完成了变量的定义
int_a = 123
str_b = '123'
print(type(int_a))
print(type(str_b))
<class 'int'>
<class 'str'>
控制结构
条件分支
flag = 1
if flag == 1:
print('hello flag 1')
else:
print('hello flag 2')
hello flag 1
循环结构 for
Python中的for循环结构属于范围循环,在in关键字之后必须是一个\underline{可迭代}类型
for i in range(1,10):
print(i)
print(type(range(1,10)))
1
2
3
4
5
6
7
8
9
<class 'range'>
循环结构while
flag = 10
while flag>0:
flag = flag-1
print(flag)
9
8
7
6
5
4
3
2
1
0
Python文件读取
使用python标准函数open打开文件
file = open('./LessonData/helloworld.txt')
print(type(file))
file_content = file.read()
print(file_content)
<class '_io.TextIOWrapper'>
hello world from file
i am line 1
i am line 2