"Python Data Analysis"

Source: Internet
Author: User

Additional Features for indexed objects

① Replacement Index

② Alignment

③ Delete

First, replace the index

We already know that once the data structure is declared, the Index object cannot be changed.

In fact, once we have redefined the index, we are able to generate a new data structure with the existing

The Pandas Reindex () function replaces the index of a series object. It re-adjusts the elements of the original series based on the new tag sequence, creating a new Series object

The new index has no value corresponding to it, use Nan instead, delete the element without index

From the returned results we can see that all the index sequences have been adjusted

To better understand the self-made indexing function, we first define the following series objects

Its index is not complete, missing 2, 32 values. The common requirement is to insert a value to get a complete index, by Reindex () and the method option to Ffill. Additionally, you need to define the range values for the index.

The index entry for the new element, whose element is the index of the item whose index number is smaller than the previous one. So we see that the value of index 2,3 is 1, and the value of index 1

If you want to use the element following the newly inserted index, you need to use the Bfill method

The replacement index can be extended from series to dataframe, not only to replace the row index, but also to replace the column index or even replace both

Second, delete

① Deleting a series

Pandas specifically provides a function for deletion: drop (), which returns a new object that does not contain the deleted index and its elements

You can also delete an array of multiple labels

Remove elements from Dataframe, you need to specify axis labels for two axes of an element

② Delete Datafrmae

To delete a column, you need to specify the index of the column, but you still need to use the Axis option to specify from which axis to begin deleting the element

"Python Data Analysis"

Related Article

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.