python数据分析学习笔记---语言精要
2019-06-24 11:50
405 查看
版权声明:本文为博主原创文章,遵循 CC 4.0 by-sa 版权协议,转载请附上原文出处链接和本声明。
本文链接:https://blog.csdn.net/weixin_44384937/article/details/92017002
Python 数据分析:
- python 语言精要
- Ipython
- numpy
- pandas
- 数据加载
- 数据处理
- 数据绘图可视化
chapter 1 python语言精要
重点了解类型 ,和不同数据结构
- if you want to run the document of the python
$ python hello_world.py
if you run the the code in the python interpreter “Ipython”
you can enter
%run hello_word.py
the difference between the python and other programming language
use the tab to organize the language rather than the brace |
---|
no use the semicolon to end the sentence |
the char # to start the annotation |
a = [1,2,3] b = a a.append(4) In[ ] :b [1,2,3,4]
the situation is similar with the pointer of the language C
type
Var is the name of the objective, the info of the type is reserved in the interior of the objectives
use the function isinstance (var,(type,type2,…)) to confirm the type .
type list :str int float bool,the int can be translate to the long int automatically
type | notes |
---|---|
str | add the “” |
int | write directly |
float | |
bool | 1. true or false 2.empty or the zero is equal to the false |
none | |
datetime | 1. the module include the datetime ,date,time 2.the function strptime can be used to change the format |
introduce the functions from the module
example:
there is a module"TEST", we can find the defined var PI,the function f(x) , g(a,b)
way 1
import TEST result = TEST.f(6) a=TEST.PI
way 2
from TEST import f,g,PI a=g(4,PI)
simplify the name
import TEST as ts from TEST import PI as a ,g as gf r1 = ts.f(a) r2=gf(6,a)
no use the from module_name import module_var/module_function
we should call function use module_name.module_function
dictionary
# 1、create the new dictionary my_dict = { key1 : value1, key2 : value2, key3 :value3} # 2、add new key4 & value4 my_dict[key4] = value4 # 3、drop the key3 ,value3 del my_dict[key3] or my_new_dict = my_dict.pop( key3 ) # 4、dispaly the list of keys or values my_dict.keys() my_dict values() # 5、combine the two dictionary my_dict.update({key5 : value5 , key6 :value6}) {} can replaced by the name of the dict # 6、from sequence to the dictionary new_dict =dict(zip(sequence1,sequence2))
words =['apple','bat','bar','atom','book'] by_letter ={} for word in words: letter=word[0] if letter not in by_letter: by_letter[letter]=[word] else: by_letter[letter].append(word) if-else :by_letter.setdefault(letter,[]).append(word)
date structure
tuple 拆包 内在value赋值
type | characteristic | create | add | delete | combine | section | judge | others |
---|---|---|---|---|---|---|---|---|
list | [ ] | special:[ expression for var in collections if condition] | list_name.append() list_name.insert(position,value) |
list_name.pop(position) list_name.remove(value) |
[ ]+[ ] list_name.extend(list_2)(the second way will not create the new list) |
list_name[1:2] | value in list_name | bisect.bisect/insort(list_name ,value) maintain Original orderliness |
tuple | ( ) | no special create way | tuple_name[value].append() you can not change the tuple |
no change | ( )+( ) | tuple_name[0:2] | same as above | |
dictionary | { key1: value ,key2 :value} | 1、 {key_expr : value_expr for i,value in enumerate(collection) if condition} 2、dict((key,value) for key value in enumerate(collections)) |
dict_name[key]=value | del dict_name[key] dict_name.pop(value) |
dict_name.update(dict2) | key in dict_name | dict(zip(,)) | |
set | {, , , } no duplication | set(list/tuple) | set1|set2 |
相关文章推荐
- python数据分析与挖掘学习笔记(3)_小说文本数据挖掘part1
- python数据分析与挖掘学习笔记(4)-垃圾邮件自动识别
- python数据分析与挖掘学习笔记(7)-交通路标自动识别实战与神经网络算法
- 学习Python数据分析随手笔记【一】numpy数组的函数简单应用
- python数据分析学习笔记三
- python数据分析与挖掘学习笔记(6)-电商网站数据分析及商品自动推荐实战与关联规则算法
- 学习Python数据分析随手笔记【二】numpy数组的属性
- 【数据分析 R语言实战】学习笔记 第六章 参数估计与R实现(上)
- Python玩转数据分析学习笔记-03数据获取
- 利用Python进行数据分析 学习笔记
- Python-数据分析与展示学习笔记(二)
- 数据结构与算法:python语言描述学习笔记Part3_2
- python3语言学习笔记(三:六类数据类型内置函数)
- python数据分析 pandas学习笔记(一)pandas系列
- 【数据分析 R语言实战】学习笔记 第八章 方差分析与R实现
- 【数据分析 R语言实战】学习笔记 第五章 数据的描述性分析(上)
- 【数据分析 R语言实战】学习笔记 第六章 参数估计与R实现(下)
- 用data.DataReader读取股价数据并分析--python学习笔记17
- 【数据分析 R语言实战】学习笔记 第一章 数据分析导引
- 【数据分析 R语言实战】学习笔记 第八章 方差分析与R实现