pandas study notes (2)-Series object

Series type:
*. Consists of a set of data and its associated data index.
*. First, Series has automatic indexing, but it also has automatic indexing, such as:
import pandas as pd
b=pd.Series([4,6 ,8,3,6],index=["a","b","c","d","e"])

*.Series can be created from the following types:
Python list, scalar value, Python dictionary, ndarray, other functions.
*created from scalar value:
    s=pd.Series(25,index=["a","b"," c"])
    The Series object created in this way contains three elements, the value is 25, and the indices are "a", "b", "c"
*. Created from a dictionary:
    d=pd.Series({"a": 9,"b":8,"c":7})
  can also e=pd.Series({"a":9,"b":8,"c":7},index=["c", "a", "b", "d"])
    can be matched, but the value of index "d" is NaN
*. Created from ndarray (very common):
    n=pd.Series(np. arange(5),index=np.range(9,4,-1))

Basic operations of the Series type: The
Series type includes two parts: index and values.
    *Use .index to get all the indexes, and the type of the returned result is called Index
    *Use .values ​​to get the data. The returned result is the numpy array type
. The operation of the Series type is similar ndarray type,
    *same indexing method
    *operations and operations in numpy can be used for Series type,
    *can be sliced ​​through a list of custom indices
    * can also be sliced ​​through automatic indexing.
The operation of Series type is similar to a Python dictionary.
    *Automatic indexing (generated by yourself) index) and custom index coexist
    *You can index multiple values
    ​​b["b"],b[["c","d","a"]]
    *Although the two sets of indexes coexist, they cannot be mixed
    *. There is also the usage of in (look at not in the index, not at the value, not at the automatic index)
     "c" in b
    *. And get()
     b.get("f", 100)
     If there is no such custom index, Just return 100
    * You can also put conditions in square brackets, I really want the database query statement
    b[b>median()]
Series type alignment operation:
    for Series+Series
    If the value of the custom index is the same, the operation is performed. Otherwise, the index is left, and the value of NaN
    will automatically index the same value. It is an index-based operation, unlike numpy's dimension-based operation
. The name attribute of the Series:
    Series object Both index and index can have a name, stored in name
    b.name="first Series object"
    b.index.name="index column"
    can be modified at any time and take effect immediately
Understanding: Series is actually a custom index and value combination

Published 33 original articles , received 9 likes , and visited 5384