Pandas Array (Pandas Series)-(1)

Source: Internet
Author: User

Import Pandas

import Pandas as PD
Countries = ['Albania','Algeria','Andorra','Angola','Antigua and Barbuda',             'Argentina','Armenia','Australia','Austria','Azerbaijan',             'Bahamas','Bahrain','Bangladesh','Barbados','Belarus',             'Belgium','Belize','Benin','Bhutan','Bolivia']life_expectancy_values= [74.7, 75., 83.4, 57.6, 74.6, 75.4, 72.3, 81.5, 80.2,                          70.3, 72.1, 76.4, 68.1, 75.2, 69.8, 79.4, 70.8, 62.7,                          67.3, 70.6]gdp_values= [1681.61390973, 2155.48523109, 21495.80508273, 562.98768478,              13495.1274663, 9388.68852258, 1424.19056199, 24765.54890176,              27036.48733192, 1945.63754911, 21721.61840978, 13373.21993972,                483.97086804, 9783.98417323, 2253.46411147, 25034.66692293,               3680.91642923, 366.04496652, 1175.92638695, 1132.21387981]

#将普通数组转换为pandas数组

Life_expectancy = PD. Series (life_expectancy_values)

GDP = PD. Series (gdp_values)

Pandas arrays and numpy arrays have many of the same operations:

(1) Interception section

Print Life_expectancy[0]
# results: print gdp[3:6]
# results: 3 562.9876854 13495.1274665 9388.688523dtype:float64

(2) Cycle:

 for inch life_expectancy: Print ' examining life expectancy {} '. Format (country_life_expectancy)

# results






...

Examining life expectancy 70.6

(3) commonly used functions:

Print Life_expectancy.mean ()   # Find Average
# results

Print life_expectancy.std () # ask for standard deviation
# results
Print  # Ask for maximum value
# results
print gdp.sum ()                
# results
182957.59833

(4) Vectorization operations:

A = PD. Series ([1, 2, 3, 4]) b= PD. Series ([1, 2, 1, 2])  PrintA +b#Results0 21 42) 43 6Dtype:int64PrintA * 2#Results0 21 42) 63 8Dtype:int64PrintA >= 3#Results0 False1False2True3Truedtype:boolPrintA[a >= 3]#Results2 33 4Dtype:int64

Pandas Array (Pandas Series)-(1)

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.