Pandas dataframe data frame

Source: Internet
Author: User

A Data box is a two-dimensional data structure, similar to a table in SQL. Data boxes can be constructed using dictionaries, arrays, lists, and sequences.

1. If the dictionary data box is created, the column name is the key name:

d = {‘one‘:pd.Series([1,2,3],index= [‘a‘,‘b‘,‘c‘]),     ‘two‘:pd.Series([1,2,3,4],index=[‘a‘,‘b‘,‘c‘,‘d‘])}print(pd.DataFrame(d))

2. List creation data box:

d = pd.DataFrame([[1,2,3,4],[5,6,7,8],[10,20,30,40],[50,60,70,80]],columns=[‘V1‘,‘V2‘,‘V3‘,‘V4‘])print(d)

3. Column Selection, deletion, and addition:

DF = PD. dataframe ([[,], [,], [,], [50, 60,], columns = ['v1 ', 'v2 ', 'v3 ', 'v4']) print (DF, '\ n ') DF ['v5 '] = DF ['v1'] * DF ['v2'] # multiply the first column by the second column; print ('multiply the first column by the second column :') print (DF ['v5 '],' \ n') dF ['flag'] = DF ['v2']> 20 # Add a column; the value of the logical result is assigned to flagprint ('Add a column: ') print (DF,' \ n') del DF ['flag'] # delete column V5 = DF. pop ('v5 ') # delete column print ('delete column:') print (DF, '\ n', V5,' \ n') DF. insert (2, 'v6 ', DF ['v1']) #2 indicates the insert position, and V6 indicates the column name, DF ['v1 '] is the inserted value print ('insert column:') print (DF, '\ n') print (' * 50)

4. General selection methods:

 

Operation Method Method Result
Select a column Def [col] Sequence
Select a row using column tags DF. Loc [col] Sequence
Select a row by location DF. icol [2] Sequence
Line Cutting DF [5: 10] Data box
Read one row of data

DF. Loc [0,:]
DF. iloc [0,:]
DF. IX [0,:]

 

Pandas dataframe data frame

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.