Pandas Array (Pandas Series)-(2)

Source: Internet
Author: User

The pandas Series is much more powerful than the numpy array , in many ways

First, the pandas Series has some methods, such as:

The describe method can give some analysis data of Series :

Import=  PD. Series ([1,2,3,4]) d = s.describe ()
Print (d)
Count    4.000000mean     2.500000std      1.290994min      1.00000025%      1.75000050%      2.50000075%      3.250000max      4.000000dtype:float64

Second, the biggest difference between the Pandas series and the numpy array is that the Pandas series has an ' index ' concept:

When you create a Pandas series, you can include an array of index values:

Life = PD. Series ([74.7, 72.8], index=['city1'city2'  city3"city4")
Print (Life)

where [' city1 ', ' city2 ', ' city3 ', ' City4 '] array is an indexed array that will be indexed as a life Series :

City1    74.7city2    75.0city3    80.0city4    72.8dtype: Float64

Pandas Series is a combination of list and dict , list is ordered, according to position 0,1,2,3 ... to get the corresponding position of the element, dict is unordered, by key to get the corresponding element, pandas Series is both ordered and indexed key , you can get the element by key :

Print (life['city1') # result 74.7

You can also get elements by location index:

Print (life[0]) # result 74.7

To better differentiate between positional and key indexes, the pandas Series provides two methods:

Print (life.loc['city1') Print (Life.iloc[0])

Loc passes in the key index value, iloc the location index value.

Pandas Array (Pandas Series)-(2)

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.