实例介绍
Introduction to Python for Econometrics, Statistics and Data Analysis
Notes to the 2nd edition This edition includes the following changes from the first edition (March 2012) The preferred installation method is now Continuum Analytics' Anaconda Anaconda is a complete cientific stack and is available for all major platforms New chapter on pandas pandas provides a simple but powerful tool to manage data and perform basic analysis. It also greatly simplifies importing and exporting data New chapter on advanced selection of elements from an array. Numba provides just-in-time compilation for numeric Python code which often produces large per formance gains when pure Numpy solutions are not available(e. g looping code) Dictionary, set and tuple comprehensions · Numerous typos All code has been verified working against Anaconda 1.7.0 i Contents 1 Introduction 1. 1 Background 1.2 Conventions 1.3 Important Components of the Python Scientific Stack 3 1.4 Setu 1.5 Testing the Environment 12 1.6 Python Programming 12 7 Exercises 16 1. a register_python.py·· 18 2 Python 2.7 VS 3 (and the rest 2.1 Python 2.7 VS 3 21 2.2 Intel Math Kernel Library and AMD Core Math Library 21 2.3 Other Variants 2.A Relevant Differences between Python 2.7 and 3 ······:····· 23 3 Built-in Data Types 25 3.1 Variable Names 3.2 Core Native Data Types 3.3 Python and Memory Management 36 3.4 Exercises 38 4 Arrays and Matrices 4.1AI 41 4.2 Matrix 43 4.3 1-dimensional arrays 44 442- dimensional arrays,.,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,45 4.5 Multidimensional Arrays ··· 4.6 Concatenation 45 4.7 Accessing Elements of an Array 4.8 Slicing and Memory Management 4.9 import and modules 53 4.10 Calling Functions 54 4.11 Exercises 5 Basic Math 57 5.1 Operators .57 5.2 Broadcasting.......... .,,,,,.,.58 5.3 Array and Matrix Addition(+)and Subtraction(-) ..59 5.4 Array Multiplication(=) 60 5.5 Matrix Multiplication(*) 鲁b 60 5.6 Array and Matrix Division(/) ,60 5.7 Array Exponentiation (** 5.8 Matrix Exponentiation (*R) 5.9 Parenthe 61 5.10 Transpose 61 5.11 Operator Precedence 61 5.12E 62 6 Basic Functions and Numerical Indexing 65 6.1 Generating Arrays and Matrices ·:· ,,65 6.2 Rounding 6.3 Mathematics ·.··· 6.4 Complex Values 71 6.5 Set Functions .71 6.6 Sorting and Extreme Values...............,.. 6.7 Nan Functions 74 6. 8 Functions and Methods/Properties .75 6.9 Exercises 76 7 Special Arrays 7.1 Exercises 8 Array and Matrix Functions 8. 1 Views 79 8.2 Shape Information and transformation 8.3 Linear Algebra Functions 87 8. 4 Exercises 90 9 Importing and Exporting Data 93 9.1 Importing Data using pandas 93 9.2 Importing Data without pandas 94 9.3 Saving or Exporting Data using pandas 9.4 Saving or Exporting Data without pandas 100 9.5 Exercises 101 10 Inf nan and Numeric Limits 103 10.1 inf and NaN ,.103 10.2 Floating point precision 103 10.3 Exercises 104 11 Logical operators and find 107 11.1>.>=,<,< != 07 11.2 and. or not and xor ..108 11.3 Multiple tests ,,,,.109 11.4is欢 110 11.5 Exercises ,111 12 Advanced Selection and Assignment 113 12.1 Numerical Indexing .113 12.2 Logical Indexing 118 12.3 Performance Considerations and Memory Management 12.4 Assignment with Broadcasting ..122 12.5 Exercises 124 13 Flow Control, Loops and Exception Handling 127 13. 1 Whitespace and Flow control .... ,,127 13.2 if..elif. else ..,.,,,...127 13.3for..., 128 13.4 While 131 135try. except· 133 13.6 List Comprehensions 13.7 Tuple, Dictionary and Set Comprehensions 13.8 Exercises 135 14 Dates and Times 137 14.1 Creating Dates and Times 137 14.2 Dates mathematics ,.137 14.3 Numpy datetime 64 138 15 Graphics 141 15. 1 2D Plotting 141 15.2 Advanced 2D Plotting 147 1533 D Plotting,,,,,,,, 15. 4 General Plotting Functions 159 15.5 Exporting Plots 159 15.6 Exercises 160 6 Structured Arrays 161 16.1 Mixed Arrays with Column Names 161 16.2 Record Arrays pandas 165 17.1 Data structures 165 17.2 Statistical Function 184 17.3 Time-series data 185 17.4 Importing and Exporting Data 17.5 Graphics 191 17.6 Examples ..192 18 Custom Function and Modules 199 18.1 Functions 199 182 Variable Scope,.,,,,,,,,,,,,,,,,, 206 18.3 EXample: Least Squares with Newey-West Covariance 207 18.4 Anonymous Functions.....,........... 208 18.5 Modules 208 18.6 Packages 2 18.7 PYTHONPATH 211 18.8 Python Coding Conventions 211 18.9 Exercises 212 18.A Listing of econometrics. py ...213 19 Probability and statistics Functions 217 19.1 Simulating Random Variables 217 19.2 Simulation and Random Number generation 221 19.3 Statistics Functions 223 19.4 Continuous Random variables 226 19.5 Select Statistics Functions 229 19.6 Select Statistical Tests 232 19.7 Exercises .233 20 Optimization 235 20.1 Unconstrained Optimization ...236 20.2 Derivative-free Optimization 239 20.3 Constrained Optimization 240 20. 4 Scalar Function Minimization 244 20.5 Nonlinear Least Squares ..........245 20.6 Exercises 246 21 String Manipulation 247 21.1 String Building ,.247 21.2 String Functions 248 21.3 Formatting Numbers .,,,,,,,,,,,,..252 21.4 Regular Expressions ..256 21.5 Safe Conversion of strings ,,,,,,,,,,,,,,.257 22 File system Operations 259 22.1 Changing the Working Directory 259 22.2 Creating and deleting directories 259 22.3 Listing the Contents of a Directory 22.4 Copying, Moving and Deleting Files 22.5 Executing Other Programs 261 22.6 Creating and Opening Archives ,,261 22.7 Reading and writing files 262 22.8 Exercises 264 23 Performance and code optimization 265 23.1 Getting Started 265 23.2 Timing Code ,.265 23.3 Vectorize to Avoid Unnecessary Loops ,.266 23.4 Alter the loop dimensions ..267 235 Utilize Broadcasting,.,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,, 268 23.6 Use In-place Assignment 23.7 Avoid Allocating Mem 268 23.8 Inline Frequent Function Calls 23 9 Consider Data Locality in Array 268 23.10 Protile Long Running Functions .269 23.1 1 Numba ,,274 23.12Cython 276 23. 13Exercises 鲁 281 24 Parallel 283 24.1 map and related functions 24.2 Multiprocess module 284 24.3 IPython Parallel 285 25 Examples 287 25 1 Estimating the Parameters of a GARCH Model 287 25.2 Estimating the Risk Premia using Fama-Mac Beth Regressions ,.291 25.3 Estimating the Risk Premia using GMM ....295 25.4 Outputting LATE 298 26 Other Interesting Python Packages 301 26.1 statsmodels ,,301 26.2 ptz and bal 26.3rpy2 301 26.4 Py Tables and h5py 301 27 Quick Reference 303 27.1 Built-ins 303 27.2 NumPy(numpy) 27.3 ScIP ..325 27.4 Matplotlib .,.328 27.5 Pandas 330 27.6 IPython 334 VIll 【实例截图】
【核心代码】
标签:
小贴士
感谢您为本站写下的评论,您的评论对其它用户来说具有重要的参考价值,所以请认真填写。
- 类似“顶”、“沙发”之类没有营养的文字,对勤劳贡献的楼主来说是令人沮丧的反馈信息。
- 相信您也不想看到一排文字/表情墙,所以请不要反馈意义不大的重复字符,也请尽量不要纯表情的回复。
- 提问之前请再仔细看一遍楼主的说明,或许是您遗漏了。
- 请勿到处挖坑绊人、招贴广告。既占空间让人厌烦,又没人会搭理,于人于己都无利。
关于好例子网
本站旨在为广大IT学习爱好者提供一个非营利性互相学习交流分享平台。本站所有资源都可以被免费获取学习研究。本站资源来自网友分享,对搜索内容的合法性不具有预见性、识别性、控制性,仅供学习研究,请务必在下载后24小时内给予删除,不得用于其他任何用途,否则后果自负。基于互联网的特殊性,平台无法对用户传输的作品、信息、内容的权属或合法性、安全性、合规性、真实性、科学性、完整权、有效性等进行实质审查;无论平台是否已进行审查,用户均应自行承担因其传输的作品、信息、内容而可能或已经产生的侵权或权属纠纷等法律责任。本站所有资源不代表本站的观点或立场,基于网友分享,根据中国法律《信息网络传播权保护条例》第二十二与二十三条之规定,若资源存在侵权或相关问题请联系本站客服人员,点此联系我们。关于更多版权及免责申明参见 版权及免责申明
网友评论
我要评论