Wu Yuxiong - born natural python learning Notes: pandas module deletes the data DataFrame

Pandas delete DataFrarne data through drop function, the syntax is:

 

 

For example, delete Chen Tsung (row headers) results:
Import PANDAS AS PD 

DATAS = [[65,92,78,83,70], [90,72,76,93,56], [81,85,91,89,77], [79,53,47, 94,80 ]] 
indexs = [ " Linda Ming " , " Chen Tsung " , " Meili " , " Xiong Xiaojuan " ] 
the Columns = [ " language " , " mathematics " , " English " , " natural " , " society " ] 
df = pd.DataFrame (datas,columns=columns,  index=indexs)
 Print ( ' delete Chen Tsung results -> ' ) 
DF1 = df.drop ( " Chen Tsung " )
 Print (DF1)

Delete mathematics (column headings) results:
Print ( ' delete math -> ' ) 
DF2 = df.drop ( " mathematics " , Axis = 1 )
 Print (DF2)

If you delete a row or column more than one, as a list of required parameters, such as deleting mathematics and natural results:
Print ( ' delete mathematics and natural results -> ' ) 
DF3 = df.drop ([ " Mathematics " , " natural " ], Axis = 1 )
 Print (DF3)

If you delete a row or column and continuously project a lot, it can be treated using the delete "range" approach. Delete 
grammar continuous line is:

The results will delete "start value" to "end value l" line, for example, to delete the second line to the fourth line (Chen 
smart, Meili, Xiongxiao Juan) results:
Print ( ' Remove from Chen Tsung to Xiongxiao Juan Results -> ' ) 
DF4 = df.drop (df.index [. 1:. 4 ])
 Print (DF4)

Delete continuous column syntax is:

For example, to delete the first two column 4 (mathematics, English, natural) results:
Print ( ' delete the results from the mathematical nature -> ' ) 
DF5 = df.drop (df.columns [. 1:. 4], Axis =. 1 )
 Print (DF5)

 

 

Guess you like

Origin www.cnblogs.com/tszr/p/12030996.html