A sequence series, much like an array in NumPy, can be initialized by a list, a tuple, a dictionary, an array in a numpy.
from Pandas Import Series>>> s = series ([0.11.22.33.44.5 ])>>> s00.111.222.3 3 3.4 4 4.5 Dtype:float64
2, the sequence can also be composed of labels, by default is represented by a number.
>>> s = Series ([0.11.22.33.44.5], index = [' A ', ' B ', ' C ', ' d ' , ' E '])>>>0.11.22.33.4 4.5 dtype:float64
The index can be indexed by numbers, tags, truth tables, slices
fromPandas import seriess= Series ([0.1,1.2,2.3,3.4,4.5], index = ['a','b','C','D','e']) s[1]out[ $]:1.2
fromPandas import seriess= Series ([0.1,1.2,2.3,3.4,4.5], index = ['a','b','C','D','e']) Print s[1],'\ n'Print s[1:4],'\ n'Print S[s>3],'\ n'Print s[[1,2,3]]1.2b1.2C2.3D3.4Dtype:float64 D3.4e4.5Dtype:float64 b1.2C2.3D3.4Dtype:float64
Common functions of sequence
1,head and tail to display the head 5 rows or the end 5 rows of data, you can also pass parameters to modify the number of rows displayed
fromPandas import seriess= Series ([0.1,1.2,2.3,3.4,4.5], index = ['a','b','C','D','e']) print s.head (),'\ n'Print S.head (2)
A0.1b1.2C2.3D3.4e4.5Dtype:float64 a0.1b1.2Dtype:float64
2,isnull and notnull return the sequence of equal length,
3. Some statistical characteristics of describe return sequence
fromPandas import Seriesimport numpy asNPS=series (Np.arange (1.0,Ten) ) S.describe () out[ +]:count9.000000mean5.000000STD2.738613min1.000000 -%3.000000 -%5.000000 the%7.000000Max9.000000Dtype:float64
4.unique and Nunique, return a duplicate dataset or duplicate data set
5, Drop (labels) Delete the data of the label, Dropna () is to delete the Nan data
6. Append (series) Add data
fromPandas import Seriesimport numpy asNPS=series (Np.arange (1.0,Ten)) S2=series ([ A, -, -, -]) print s.append (s2)?0 1.01 2.02 3.03 4.04 5.05 6.06 7.07 8.08 9.00 22.01 33.02 44.03 55.0Dtype:float64
7. Replace (series,values) replaces the data in the series dataset with the values DataSet
Note: This substitution is to return the replaced data instead of replacing it on the original data set
fromPandas import Seriesimport numpy asNPS=series (Np.arange (1.0,Ten)) S2=series ([ A, -, -, -]) S3=s.append (s2) Print s3.replace ([2,5,8],[ A, -, About]) S3?0 1.01 22.02 3.03 4.04 55.05 6.06 7.07 99.08 9.00 22.01 33.02 44.03 55.0dtype:float64out[Wuyi]:0 1.01 2.02 3.03 4.04 5.05 6.06 7.07 8.08 9.00 22.01 33.02 44.03 55.0Dtype:float64
8. Update (series) is updated with series to update only the data matching the tag.
Note: Updates are made on the original data set
>>> S1 = Series (Arange (1.0,4.0), index=[' A ', ' B ', ' C '])>>>s1a1b2C3Dtype:float64>>> s2 = Series (-1.0* Arange (1.0,4.0), index=[' C ', ' d ', ' e '])>>>s1.update (S2)>>>s1a1b2C-1Dtype:float64
9, the data frame,DataFrame, equivalent to the array of two-dimensional arrays, unlike array array where it can be different data types of data group together
from Pandas import Dataframea=np.array ([[[1,2],[3,4]]);d f= DataFrame (a) dfout[]: 0 10 1 21 3 4
>>> df = DataFrame (Array ([[[1,2],[3,4]]), columns=[' A ', ' B '])
>>> DF
A b
0 1 2
1 3 4
You can also specify row and column labels
>>> df = DataFrame (Array ([[1,2],[3,4]]), columns=[' dogs ', ' cats '], index=[' Alice ', ' Bob '])>>>1234
Reading notes 6pandas Simple and practical