Dataframe Application of Pandas Library of Python data analysis

Source: Internet
Author: User

  

This section describes the basic methods of data in series and Dataframe

    1. 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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.