In-depth understanding of pandas in Python (code example)

Source: Internet
Author: User
This article brings the content is about Python pandas in-depth understanding (code example), there is a certain reference value, the need for friends can refer to, I hope to help you.

First, screening

First, create a 6X4 matrix data.

Dates = Pd.date_range (' 20180830 ', periods=6) df = PD. DataFrame (Np.arange) reshape ((6,4)), index=dates, columns=[' A ', ' B ', ' C ', ' D ']) print (DF)

Print:

             A   B   C   d2018-08-30   0   1   2   32018-08-31   4   5   6   72018-09-01   8   9  112018-09-02  152018-09-03  192018-09-04  23

Simple filtering

If we want to select DataFrame the data, the following describes two ways that they can achieve the same goal:

Print (df[' A ']) print (DF. A) "" "2018-08-30     02018-08-31     42018-09-01     82018-09-02    122018-09-03    162018-09-04    20freq:d, Name:a, Dtype:int64 "" "

Let the selection span multiple rows or columns:

Print (Df[0:3]) "" "            A  B   C   d2018-08-30  0  1   2   32018-08-31  4  5   6   72018-09-01  8 9 "" "  print (df[' 20180830 ': ' 20180901 '])" ""            A  B   C   d2018-08-30  0  1   2   32018-08-31  4  5   6   72018-09-01  8  9  10 11 "" "  

If df[3:3] it will be an empty object. The latter selects the 20180830 20180901 data between the labels and includes both tags .

You can also go through loc , iloc and ix make your choice.

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.