程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
您现在的位置: 程式師世界 >> 編程語言 >  >> 更多編程語言 >> Python

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


6 - Time data type conversion

  • pd.to_datetime(col)

7 - Set a column as a row index

  • df.set_index()

Four 、jupyter note

Click to download jupyter note


  1. 上一篇文章:
  2. 下一篇文章:
Copyright © 程式師世界 All Rights Reserved