您的位置:首页 > 编程语言 > Python开发

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

2019-06-24 11:50 405 查看
版权声明:本文为博主原创文章,遵循 CC 4.0 by-sa 版权协议,转载请附上原文出处链接和本声明。 本文链接:https://blog.csdn.net/weixin_44384937/article/details/92017002

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

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
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: