2. Python quantitative transaction - pandas of the three swordsmen
編輯:Python
Catalog
One 、pandas brief introduction
Two 、Series
1 - Series brief introduction
2 - Series establish
3 - Series Index and slice of
4 - Series Common properties
5 - Series Common methods
3、 ... and 、DataFrame
1 - Dataframe brief introduction
2 - DataFrame establish
3 - DataFrame Properties of
4 - DataFrame Indexes
5 - DataFrame section
6 - Time data type conversion
7 - Set a column as a row index
Four 、jupyter note
One 、pandas brief introduction
Why study pandas:numpy It can already help us with data processing , So learning pandas What is the purpose of ?
numpy What can help us deal with is numerical data , Of course, there are many other types of data besides numerical data in data analysis ( character string , The time series ), that pandas It can help us deal with other data except numerical data
pandas Two classes commonly used in
Series
DataFrame
Two 、Series
1 - Series brief introduction
What is? Series:Series Is an object similar to a one-dimensional array , It's made up of two parts
values: A set of data (ndarray type )
index: Related data index labels
2 - Series establish
Series Two ways to create
From list or numpy Array creation
Created by dictionary
3 - Series Index and slice of
4 - Series Common properties
Series Common properties
shape: shape
size: Element number
index: Returns the index
values: Return value
dtype: Type of element
5 - Series Common methods
Common methods
head(),tail()
unique()
isnull(),notnull()
add() sub() mul() div()
3、 ... and 、DataFrame
1 - Dataframe brief introduction
What is? DataFrame:DataFrame It's a 【 Tabular form 】 Data structure of .DataFrame It consists of multiple columns of data arranged in a certain order . The original intention of the design is to Series From one dimension to multi dimension .DataFrame Existing row index , There are also column indexes
DataFrame structure : It can be understood as a table in the database
Row index :index
Column index :columns
value :values
2 - DataFrame establish
DataFrame Two ways to create
ndarray establish
Dictionary creation
3 - DataFrame Properties of
DataFrame Common properties :values、columns、index、shape
practice : According to the following test scores , Create a DataFrame, Name it df
Zhang San Li Si
Chinese language and literature 150 0
mathematics 150 0
English 150 0
Synthesis 300 0
4 - DataFrame Indexes
Single column 、 Take multiple columns
Take single line 、 Take multiple lines
loc and iloc The difference between : Reference material
iloc: Fetching rows by implicit index
loc: Fetching rows by explicit index
Take a single element 、 Take multiple elements
5 - DataFrame section
Yes 、 Slice columns
practice : Index slice :
①. hypothesis ddd It's the midterm exam result ,ddd2 It's the final exam result , Please create freely ddd2, And with ddd Add up , Find the average value at the end of the interim period
②. Suppose that Zhang 3 was found cheating in the mid-term examination of Mathematics , Remember as 0 branch , How to achieve ?
③. Li Si makes contributions for reporting Zhang San's cheating , Midterm all subjects plus 100 branch , How to achieve ?
④. Later, the teacher found that a problem had gone wrong , In order to appease the students , Add... To every student and subject 10 branch , How to achieve ?
DataFrame The operation rules of are the same as Series