The method of Pandas Dataframe data extraction

Source: Internet
Author: User
Import NumPy as NP from
Pandas import dataframe
import pandas as PD


Df=dataframe (Np.arange () reshape (3,4 ), index=[' One ', ' two ', ' THR '],columns=list (' ABCD ')

df[' A ' #取a列
df[[' A ', ' B ']] #取a, column B

#ix可以用数字索引, You can also use index and column indexes
df.ix[0] #取第0行
df.ix[0:1] #取第0行
df.ix[' one ': ' Two '] #取one, two row
df.ix[0:2,0] #取第0 , 1 rows, No. 0 column
df.ix[0:1, ' a '] #取第0行, column A
df.ix[0:2, ' A ': ' C '] #取第0, 1 lines, ABC column
df.ix[' one ': ' Two ', ' a ': ' C '] #取one, Two row, ABC column
df.ix[0:2,0:1] #取第0, 1 rows, No. 0 column
df.ix[0:2,0:2] #取第0, 1 rows, No. 0, 1 columns

#loc只能通过index和columns来取, cannot use a number
df.loc[' One ', ' a '] #one行, column A
df.loc[' one ': ' Two ', ' a '] #one到two行, column A
df.loc[' one ': ' Two ', ' a ': ' C ']# One to two row, a to C column
df.loc[' one ': ' Two ', [' A ', ' C ']] #one到two行, ac column

#iloc只能用数字索引, cannot be indexed
Df.iloc[0:2] #前2行
df.iloc[0] #第0行
df.iloc[0:2,0:2] #0, 1 rows, 0, 1 columns
df.iloc[[0,2],[1,2,3]] #第0, 2 rows, 1, 2, 3 columns

#iat取某个单值, Only digital index
df.iat[1,1] #第1行, 1 columns
#at取某个单值, only index and columns indexes
df.at[' One ', ' a '] #one行, column A
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.