python数据分析学习笔记---语言精要

Python 数据分析:

  1. python 语言精要
  2. Ipython
  3. numpy
  4. pandas
  5. 数据加载
  6. 数据处理
  7. 数据绘图可视化

chapter 1 python语言精要

重点了解类型 ,和不同数据结构

  1. 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

typenotes
stradd the “”
intwrite directly
float
bool1. true or false
2.empty or the zero is equal to the false
none
datetime1. 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赋值

typecharacteristiccreateadddeletecombinesectionjudgeothers
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_namebisect.bisect/insort(list_name ,value) maintain Original orderliness
tuple( )no special create waytuple_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]=valuedel dict_name[key]
dict_name.pop(value)
dict_name.update(dict2)key in dict_namedict(zip(,))
set{, , , } no duplicationset(list/tuple)set1|set2
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值