Professional Documents
Culture Documents
Python
2
Python
3
Anaconda
Ipython IDE ipyhton IDE
Anaconda Canopy Enthought Free
Express Anaconda
https://www.continuum.io/downloads
4
Windows Anaconda
TUNA
https://mirrors.tuna.tsinghua.edu.cn/anaconda/archive/
windows64 Anaconda3-4.3.1-Windows-x86_64.exe
Anaconda3-4.3.1-Windows-x86_64
5
Linux Anaconda
6
Spyder
Pyhton
IPyhton
7
python
Python
Python Python
Mlpy
windows dos
8
Python I
N ndarray
numpy
C/C++ Fortran
Python
scipy
MATLAB Scilab GNU Octave
matplotlib
numpy
pandas
numpy
9
Python II
scikit-
learn SVM
Kmeans DBSCAN
NLTK
50
Mlpy Cython
feature /
Shogun
C++ Matlab R Octave Python
linux
10
Python III
PyBrain ( )
Milk SVMs K-NN
PyMVPA
Pattern web
HTML
Monte Python
Theano
11
Pyhton
numpy
12
python
python python
13
1 help( )
2 pdf
3 / /
; * ? np.*ran*?
help( )
help
14
15
Python
Python
( = )
pandas.DataFrame.plot(x=None, y=None,
kind=line,)
16
Python
mean()
sum()
plot()
sort()
R
,
plot()
17
Pyhton ?
Tab
log() binom.test()
log10() fisher_exact()
exp() chisquare()
sin() friedmanchisquare()
cos() mean()
tan() sd()
arcsin() var()
arccos() .
18
Python
column
by
ax
19
2 + 2
a = 2 a = b = 4
>>> b
>>> 4
>>> print a
>>> 4
20
Python
1. , China china
2.
2result result2
3. _ anova-result1
4.
21
str China
22
(class)
(vector)
[1,2,3]; ["a","a","b","b","c]
(matrix)
df = pd.DataFrame(np.random.randn(3,4),
index=pd.date_range('2008-01-10', periods=3),
columns=list('ABCD'))
A B C D
k k in 1:n, n
(n = 1) (n = 2) (n >= 3)
(dataframe)
pandas /
R dataframe
(list)
24
+, -, *, /, //, **, %
25
1 Column
names
1 40 15 22 600 25
2 51 12 26 350 30
3 46 11 20 390 45
4 38 12 24 260 20
5 49 10 25 220 33
Entry
Row names
26
(dataframe)
(column) (vector)
(row) (vector)
(1)
(2)
27
read.table() read.csv()
txt csv read.table()
read_csv()
pandas excel, ,
SAS, HTML, SQL, STATA
28
read.csv()
tips=pd.read_csv('D:\\Projects\\Python\\Courses\\ch08\\ti
ps.csv')
read_table() read_csv()
29
sq_height = height ** 2
ratio = weight/sq_height
30
read_table/read_csv txt/csv
excel read_excel
Pandas
31
>30
32
numeric: [1, 3, 6, 7, 3, 8, 6, 4]
33
np.array(),np.zeros(), np.arange(),
np.linspace(), np.indices(), np.empty()
np.array([2,3,1,0])
np.zeros((2, 3))
np.arange(10)
np.linspace(1., 4., 6)
np.indices((3,3))
np.empty((2,5))
34
random.randint(low, high=None, size=None)
35
np.array(data),np.matrix(data),np.zeros((2,3)),
np.empty((4,5)), np.eye(N), pd.DataFrame(array)
np.array() data
arr
[0] 1 2 3
[1] 4 5 6
reshape
arr = np.arange(12).reshape(3,4) 3 4
36
:pd.DataFrame()
df = pd.DataFrame(d)
head() # 5
tail() # 5
37
( )
list()
list(character,numeric,logical,matrix)
38
isnumeric()/isdigit() #
isalpha() #
df.isnull() #
np.isnan(array) # na
39
int() float() #
str() #
array map(int/float/str,source) #
source
40
arr = np.array([5260, 5470, 5640, 6180, 6390, 6515, 6805,
7515, 7515, 8230, 8770])
arr[5]; # 5 np 0
arr[1:5] # 1 4
arr[:5] # 4
arr[3:] # 3
41
df = pd.DataFrame(np.arange(12).reshape(3,4),
index=pd.date_range('2010-01-01', periods=3),
columns=list('ABCD'))
A B C D
2010-01-01 0 1 2 3
(1) 2010-01-02 4 5 6 7
df[A] df.A 2010-01-03 8 9 10 11
(2) [,]
df.ix[1]; 1
df.ix[:2010-01-02, B]; 0 1 B
42
[][]
[]
43
TRUE
FALSE
44
np.sort()/np.partition()/np.sort_complex() /
/
a = np.array([[1,4],[3,1]])
np.sort(a)
order
45
history
ipython history
History/hist #
46
Scripting
47
(scripting language)
ASCII
48
Python
49
# plot.py
df = pd.DataFrame(np.random.randn(10,4).cumsum(0),
index=np.arange(0,100,10), columns=list('ABCD'))
50
1 python
ipyhton d:\plot.py
2 ipython
%run plot.py
3 ipython
ctrl+c, ctrl+v
51
52
Python
C,C++
def ( 1= ,):
53
54
if
if( ):
p = 0.03
if( ): if(p<=0.05):
else: else:
55
for, while
for( in ):
for link in links:
print (link)
while( ):
count = 0
count = count + 1
56
Python return
return
python /
57
try:
print 2/'0'
except ZeroDivisionError:
print ' 0'
except Exception:
print '
58
:
import numpy as np
def rcal(x,y):
z = x**2 + y**2
result = np.sqrt(z)
return result
rcal(3,4)
59
60
to_csv()
to_excel()
to_json()
to_sql()
to_stata()
to_msgpack()
plt.savefig ()
61
Python
iPython : http://ipython.org/
Anaconda https://docs.continuum.io/
NumPy: http://www.numpy.org/
Pandas http://pandas.pydata.org/
SciPy: http://scipy.org/
Skiti-learn http://scikit-learn.org/
Python http://www.pythontab.com/
62
63