numpy pandas learning

One. An array of high-efficiency than the list of many
numpy efficient processing of data, support the array, python default is not an array. pandas, scipy, matplotlib rely numpy.
pandas mainly for data mining, exploring, analysis
maiplotlib used for mapping, visualization
scipy numerical calculation, such as: integral, Fourier transform calculus
statsmodels used for statistical analysis
Gensim for text mining
sklearn machine learning, keras depth study
two.
download and install numpy mkl
pandas network installation and maiplotlib
scipy download and install
statsmodels Gensim network installation and
three numpy operation.
numpy Import
# Create a set number of one-dimensional array
# numpy.array ([element 1, element 2, element ...... n-])
X = numpy.array ([ 'A', '. 9', '. 8', '1'])
# create a two-dimensional array format
# numpy.array ([[element 1, element 2, element ...... n], [element 1, element 2, element ...... n] , [element 1, element 2, element ...... n-]])
Y = numpy.array ([[3,5,7], [9,2,6], [5,3,0]] )
# sort
x.sort ()
y.sort ()
# Maximum value
Y1 = y.max ()
# minimum value
Y2 = y.main ()
# slicing
operation of four pandas.
PDA pandas AS Import
# pandas used to generate data
# Series index representative of a series of data specified row index name, Series zero-based index of the default
# DataFrame ranks to integrate out the representative data frame, columns specify the column name
a = pda.Series ([8 ,. 9, 2,. 1], index = [ 'One', 'TWO', 'Three', 'Four'])
# Create a list format data block
b = pda.DataFrame ([[5,6,2, 3], [3,5,1,4], [ 7,9,3,5]], columns = [ 'one', 'two', 'three', 'four'], index = [ 'one' , 'TWO', 'Three'])
# dictionary to create a data frame format
C = pda.DataFrame ({
'One':. 4, # will auto-complete
'TWO': [6,2,3],
'Three ': List (STR (982))
})
# b.head (number of lines) # 5 before taking the default line head
# b.

b.head = E ()
F = b.describe ()
transposed # data, rows become columns and columns become rows
g = bT
five python data import
Import PANDAS AS PAD
F = Open ( 'D: / large .csv ',' RB ')
# import CSV
A = pad.read_csv (F, encoding =' Python ')
# many column shows how many rows
a.shape ()
a.values [0] [2] The first line # The third column
# description csv data
B = a.describe ()
# sort
C = a.sort_values ()
# import Excel
D = pad.read_excel ( 'D: / large * .xls')
Print (D)
Print (d.describe ())
# import MySQL
import pymysql
Conn = pymysql.connect (Host = 'localhost', = User 'the root', the passwd = 'the root', DB = '')
SQL = 'SELECT * from mydb'
E = pad.read_sql (sql,conn)
# import html form data need to install html5lib and bs4
pad.read_html = G ( 'https://book.douban.com/subject/30258976/?icn=index-editionrecommend')
# imported text data
h = pad.read_table ( 'd: /lianjie.txt ', 'rb ', = Engine' Python ')
Print (h.describe ())
six matplotlib using
# line chart / scatter plot Plot
# histogram with a hist
Import matplotlib.pylab AS PYL
Import numpy AS NPY
X = [1,2 , 4,6,8,9]
Y = [5,6,7,8,9,0]
pyl.plot (X, y) #plot (data of X-axis, y-axis data, the form of presentation)
# scatter O FIG., the default is a straight line c cyan r red cyan magenta red m magente g green b blue green yellow blue y yellow w white white
# - straight - dotted line - - form: fine dashed line
# S * stars hexagonal square h xx + plus rhombic form d p pentagram
pyl.plot (X, Y, 'd')
pyl.title ( 'name') # name
pyl.xlabel ( 'xname') #x axis name
pyl.ylabel ( 'yname ') #Y axis name
pyl.xlim (0,20) # Set the x-axis range
pyl.ylim (2,22) # sets the y-axis range
pyl.show ()
# generates random number
data = npy.random.random_integers (1,20,100) # (minimum, maximum, number)
# generates a normal random number
data2 = npy.random.normal (10.0, 1.0, 10000) # ( mean, Sigma, number)
# histogram of a hist
pyl.hist (Data)
pyl.hist (DATA2)
# set upper Lower histogram
sty = npy.arange (2,20,2) # step width of said histogram
pyl.hist (data, sty, histtype = 'stepfilled' ) removed # contour
drawing and the use of sub-picture #
pyl.subplot (2, 2, 2) # ( rows, columns, this region)
X1 = [2,3,5,8,6,7]
Y1 = [2, 3,5,9,6,7]
pyl.plot (X1, Y1)
pyl.subplot (2, 2,. 1) # (rows, columns, this region)
X1 = [2,3,5,9,6, . 7]
Y1 = [2,3,5,9,6,7]
pyl.plot (X1, Y1)
pyl.subplot (2, 1, 2) # ( rows, columns, this region)
X1 = [2,3,5,9,6,7]
Y1 = [2,3,9,5,6,7]
PYL .plot (x1, y1)
pyl.show ()

Guess you like

Origin www.cnblogs.com/liu-xiaoyi/p/11106737.html