Series sequence

PD PANDAS AS Import 

'' '
Series sequence:
1. The sequence of statements specified index column labels
2. See column index (index), and elements (values)
3. Select the inner element
4. The element is assigned
5. Defining a new array Numpy Series object
6. filter element
7.Series objects and computing mathematical functions
8.Series constituent elements (repeat, whether or not there)
9.NaN
10.Series used dictionaries
' ''
# ## 1. Declare Series, and specify an index (not specified: automatically increments the index starts from 0) 
series_define pd.Series = ([2,3,3,4,6,8], index = [ ' A ' , ' B ' , ' C ' , ' D ' , ' E ' , ' F ' ])
 Print (series_define)
 ' '' 
A 2 
B. 3 
C. 3 
D. 4 
E. 6 
F. 8 
DTYPE: Int64 
'' '
Series sequence statement, the specified index index =
# ## Series 2. Check sequence index and [element] two arrays 
series_index = series_define.index 
series_value = series_define.values
 Print (series_index)
 Print (series_value)
 '' ' 
Index ([' A ',' B ', 'C', 'D', 'E', 'F'], DTYPE = 'Object') 
[2. 8. 6. 4. 3. 3] 
'' '
View Series sequence elements [.index .values ​​index and returns two arrays]
# ## 3. Select Internal elements: Specifies the label slice or 
Print (series_define [-1 ])
 Print (series_define [. 4: -1 ])
 Print (series_define [ ' F ' ])
 Print (series_define [[ ' E ' , ' F ' ]])    # when ## takes a plurality of values through the label, the label put on the array
Select the internal elements: a slice or designated label
# ## 4. element assignment: = elements selected assignment 
series_define [0] = 66 
series_define [ ' B ' ] = 77
 Print (series_define)
 '' ' 
A 66               
B 77 
C. 3 
D. 4 
E. 6 
F. 8 
DTYPE: Int64 
' ''
The element assignment: Choose assignment element =
# ## The existing array generating Series 
ARR = np.array ([1,2,3,4 ]) 
S = pd.Series (ARR)
 Print (S)
 '' ' 
0. 1 
. 1 2 
2. 3 
. 3. 4 
DTYPE : Int32 
'' '
Generating an array of conventional Series
# ## 6. Filter element: obtaining the element s is greater than 3 [s> 3] 
Print (s [s> 3])
Filter element: obtaining the element is greater than 3 s [s> 3]
# ## 7 applied to the array Numpy operator (+ - * /) and np.log () and the like are suitable mathematical function 
# division 
S1 = series_define / 2 Print (S1)
 '' ' 
A 33.0 
B 38.5 
C for 1.5 
2.0 D 
E 3.0 
F 4.0 
DTYPE: float64 '' ' # taking the 
S2 = np.log (series_define)
 Print (S2)
 ' '' 
A 4.189655 
B 4.343805 
C 1.098612 
D 1.386294 
E 1.791759 
F 2.079442 
DTYPE: float64 '' '



Series: mathematical function np.log (s) operator
# # 8. repetitions and determines whether there is 
#   .unique () to weight (no duplicate elements, an array of return value) 
S_A pd.Series = ([1,1,1,1,2,2,2,3 ] ) 
a = s_a.unique ()
 Print (a)
 '' ' 
[2. 3. 1] 
' '' 
#   .value_counts () returns the element to the weight, and the number of statistics appear: returns Series, as the number of occurrence values 
b = s_a.value_counts ()
 Print (B)
 Print (B [. 1 ]) 

# .isin () determines whether there is (a Boolean return value) 
C = s_a.isin ([2,3 ])
 Print (C) 
C1 = S_A [ s_a.isin ([2,3 ])]
 Print (C)
 Print (C1)
 '' ' 
0 False  
. 1 False
2 False
3    False
4     True
5     True
6     True
7     True
dtype: bool
0    False
1    False
2    False
3    False
4     True
5     True
6     True
7     True
dtype: bool
4    2
5    2
6    2
7    3
dtype: int64

'''
And the number of repetitions is determined whether there

 

Guess you like

Origin www.cnblogs.com/liuhuacai/p/11570322.html