This section describes the basic methods of data in series and Dataframe
- Re-index
An important method of Pandas objects is reindex, which is to create a new object that adapts to the new index
" "Created on 2016-8-10@author:xuzhengzhu" "" "Created on 2016-8-10@author:xuzhengzhu" " fromPandasImport*Print "--------------obj Result:-----------------"obj=series ([4.5,7.2,-5.3,3.6],index=['D','b','a','C'])PrintobjPrint "--------------obj2 Result:-----------------"Obj2=obj.reindex (['a','b','C','D','e'])PrintObj2Print "--------------obj3 Result:-----------------"obj3=obj.reindex (['a','b','C','D','e'],fill_value=0)PrintObj3
Reindex
#reindex对索引值进行重排, if the current index value does not exist, a missing value is introduced
#可以指定fill_value =% to replace missing values
--------------obj Result:-----------------d 4.5b 7.2a -5.3c 3.6Dtype:float64--------------obj2 Result:-----------------a -5.3b 7.2C 3.6d 4.5e nandtype:float64--------------obj3 Result:------ -----------a -5.3b 7.2C 3.6d 4.5e 0.0Dtype:float64
Reindex_index
2. Interpolation
For ordered data such as time series, it may be necessary to do some interpolation when re-indexing, the method option can achieve this purpose:
For ordered data such as time series, it may be necessary to do some interpolation when re-indexing, the method option can achieve this purpose:
Method Parameter Introduction |
Parameters |
Description |
Ffill or pad |
Forward padding |
Bfill or Backfill |
Back to fill |
" "Created on 2016-8-10@author:xuzhengzhu" " fromPandasImport*Print "--------------obj3 Result:-----------------"obj3=series (['Blue','Red','Yellow'],index=[0,2,4])Printobj3Print "--------------obj4 Result:-----------------"Obj4=obj3.reindex (Range (6), method='Ffill')PrintObj4
Ffill Front padding
--------------obj3 Result:-----------------0 Blue2 Red4 Yellowdtype:object --------------obj4 Result:-----------------0 Blue1 Blue2 Red 3 Red4 yellow5 yellowdtype:object
Ffill Results:
Dataframe Application of the pandas Library of Python data analysis two