Data structure of Python data analysis study notes in 2020 (1)

table of Contents

Chapter 1: Basics of Python Data Analysis

1. Python keyword view

2. Type() syntax to view the character type

3. The grammar in python is left open and right closed

4. Introduction of None

5. List of data structure (sequence data structure)

6. Tuples and collections of data structures (sequence data structures)

7. Dictionary of data structure (disordered data structure)


Course objectives:

1. Familiar with python grammar and common data structure;

2. Familiar with the application of data analysis related libraries;

3. A comparative understanding of data analysis related processes and common methods;

4. Able to complete data analysis related work.

Basics of Python data analysis:

1. Getting started with Python : Python3 installation, basic operation and syntax;

2. Basic use of Python : data types, data structures and control statements (if, else and loop statements, etc.);

3. Advanced use of Python : function writing, json structured data analysis, string processing and application of advanced functions;

4. Python data analysis commonly used libraries : introduce the commonly used data analysis libraries, Numpy, pandas, Matplotlip and scikit-learn

How to further improve python programming ability?
    1. Learn python grammar well, that is, master non-library functions and practice internal skills;
    2. Learn python field, data analysis, web development, artificial intelligence, and in-depth study;
    3. Learn computer expertise and build "systems" is the skill , Requires professional computer knowledge.

Computer expertise: data structure, algorithm, computer network, composition principle, operating system, network security, architecture, software engineering...

Chapter 1: Basics of Python Data Analysis

1. Python keyword view

import keyword
print(keyword.kwlist)

#>>> ['False', 'None', 'True', 'and', 'as', 'assert', 'async', 'await', 'break', 'class', 'continue', 'def', 'del', 'elif', 'else', 'except', 'finally', 'for', 'from', 'global', 'if', 'import', 'in', 'is', 'lambda', 'nonlocal', 'not', 'or', 'pass', 'raise', 'return', 'try', 'while', 'with', 'yield'] /n

 When naming variables, we cannot use the keywords listed above as variable names.

2. Type() syntax to view the character type

a = 1
print(type(a))
# <class 'int'>
b = 5.0
print(type(b))
# <class 'float'>
c = 'student'
print(type(c))
# <class 'str'>
d = False
print(type(d))
# <class 'str'>

3. The grammar in python is left open and right closed

a = 'python'
print(a[:1])  # 取最后一位字母
print(a[0:3])  # 取第一位到第三位字母

4. Introduction of None

a = None   # None在python语法中表示空值的意思
print(a)
# >>>None
if a is None:
    b = 4
else:
    b = 5
print(b)
# >>> 4

5. List of data structure (sequence data structure)

# 数据结构常用如下:
# 列表:是一种不同数据类型元素的有序集合
# 元组:元组是一种有序列表,但元组中的变量不能改变
# 集合:集合是一系列无序的、不重复的组合体
# 字典:存放无序的键/值(key/value)映射类型数据的容器

Sequence data structure: The structure that is arranged in sequence is called sequence data structure.

Syntax (a means list) Explanation
a = [1, 2, 3, 4, 5]
创建列表方法一
b = list('abcdefg')
创建列表方法二
a[0]
打印列表第一个元素
a[-1]
打印列表最后一个元素
a[:3]
左开右闭,打印列表前三个元素
a[0:3]
打印列表第一个到第三个元素
a[1] = '0'
修改列表中的元素
a.append()
增加列表中的元素
a.extend([])
将列表添加到列表中
a.pop(0)
删除列表第一个元素
del a[-1]
删除列表最后一个元素
a.count(4)
计数函数
a.index(5)
Index function
a.insert(a,'b') Embedding function, a represents the embedded function, b represents the content of the embedded function
a.remove('') Remove element function
a.reverse() Flip list
a.sort() Sort the list a , the default positive sorting
max(a) Calculate the maximum value of the list
min (a) Calculate the minimum value of the list
len (a) Calculate the length of the list (if the list is empty, return 0)

a = [1,2]

b = [3,4]

a + b = [1,2,3,4]

List splicing , adding and synthesizing a list two lists
a * 3 Copy the contents of the list three times

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

6. Tuples and collections of data structures (sequence data structures)

元组:元组是一种有序列表,但元组中的变量不能改变

The difference between list and tuple:

(1) The list is in the form of square brackets [], and the tuple is in the form of parentheses ();

(2) The list can be modified, and the elements in the tuple cannot be modified

(3) In python, the frequency of use of tuples is not as high as that of lists

                                         Tuple explanation
Syntax (a_tuple means tuple) Explanation

a_tuple = ()

Create tuple
a = tuple([1,2,3,4]) The list converts to a tuple
a_tuple = [0] View the first element of the tuple
a_tuple = [0:3] View the first three elements of the tuple
a_tuple[::-1] Inverted index tuple
del a_tuple Delete the entire tuple

a = (1,2)

b = (3,4)

a + b = (1,2,3,4)

Tuple concatenation
a * 3 Copy the contents of the tuple three times
   
                                       Set explanation (there cannot be repeated elements)
Syntax (a_set, b_set means set) Explanation
a_set = {1,2,3,4} Create collection
a_set.add(5) Add elements
a_set.remove(1) Delete the specified element in the collection
{1,2}.issubset(a_set) Determine whether a collection is in the specified collection
b_set = set([1,2,3,4,4,5]) Convert the list to a collection (remove duplicate values ​​4 by default)
type() View collection type

a_set - b_set

a_set.difference(b_set)

Subtraction

a_set | b_set

a_set.union(b_set)

Union

a_set & b_set

a_set.intersection(b_set)

Intersection
a_set < b_set Judgment subset

a_set ^ b_set

a_set.symmetric_difference(b_set)

The union of two sets minus the intersection

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

7. Dictionary of data structure (disordered data structure)

Grammar (dict_1 means dictionary) Explanation
dict_1 = {'name': 'Tom', 'age': '18' 'id': '1101'} 创建字典
dict_1['city'] = 'guangzhou' 增加键值对
del dict_a['city'] 删除键值对
dict_1.pop('city'] 删除键值对
dict_1 查看字典
dict_1.get('32',1) 判断32这个键是否在字典中,如果没有返回1
dict_1['name'] 通过键来查看字典中的值
len(dict_1) 查看字典长度
in 字典 判断键是否在字典中
dict_1.keys() 返回字典中的所有键
dict_1.values() 返回字典中的所有值
dict_1.items() 返回字典中的所有键值对

for key in dict_1.keys():

    print(dict_1[key])

通过字典中的键打印所有相应的值
dict_1.clear() 清空字典中的所有内容

 

Guess you like

Origin blog.csdn.net/weixin_44940488/article/details/106343772