Python pandas and Pythonpandas

Source: Internet
Author: User

Python pandas and Pythonpandas

Pandas is used for data processing:

Example:

Import pandasfood = pandas. read_csv ("d:/a.csv") # Read the csv file print (food. dtypes) # print (food. head (4) # obtain the first four rows (5 by default) print (food. tail (3) # obtain the last three rows (5 by default) print (food. shape) # print (food. columns) # name of each column
Print (food. loc [1]) # obtain 2nd rows of Data print (food ["name"]) # obtain the column named name

 

1.

Import pandasfood = pandas. read_csv ("d:/a.csv") list = food. columns. tolist () print (list) # convert all column names to list1 = [] for c in list: if (c. endswith ("(mg)"): list1.append (c) a = food [list1] print (a) # Add the columns ending with (mg) to the new list and complete the processing

 

2. Sort (Ascending by default)

Import pandasfood = pandas. read_csv ("d:/a.csv") food. sort_values ("Calcium _ (mg)", inplace = True, ascending = False) # sort in descending order, the first column name, the third parameter, and the third parameter in ascending order, the default value is trueprint (food ["Calcium _ (mg)"]).

 

3.

Import pandasman = pandas. read_csv ("d:/t.csv") print (man) age = man ["Age"] # Age column age_null = age [pandas. isnull (man ["Age"])] # age_null_len = len (age_null) # sum of empty Age

 

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.