DataFrame index and composite index

Grouping index produced in accordance with the foregoing conditions plurality of composite index

First, the index

# A, obtaining index 
df.index
 # B, designated index 
df.index = []
 # C, reset the index 
df.reindex ([ ' A ' , ' B ' , ' C ' ])  
 # Note: generally do 
# D designating a column as the index 
DF2 = df1.set_index ( ' O ' , drop = False)
 # drop default is True, discarding the row designated 
# E, designated as a multi-column index 
DF2 = df1.set_index ([ ' M ' , ' O ' ], drop = False)
 #f, to re-index operation de 
df1.set_index ( ' O ' , drop = False) .index.unique ()

Second, the composite index

1, Basics

# A, a composite index 
df.set_index ([ ' C ' , ' D ' ])
 # B, in order to exchange composite index 
df.swaplevel ()

2、Series

# A, taken Series 
df.set_index ([ ' C ' , ' D ' ]) [ ' A ' ]        # Series 
# B, taking particular value 
df.set_index ([ ' C ' , ' D ' ]) [ ' A ' ] [ ' index column value c ' ] [ ' index column value d ' ]
 # or 
df.set_index ([ ' c ' , ' d ' ]) [ 'a'] [ ' Index column c ' , ' index column value d ' ]

3、DataFrame

# A, taken DataFrame 
df.set_index ([ ' C ' , ' D ' ]) [[ ' A ' ]]
 # B, taking particular value 
df.set_index ([ ' C ' , ' D ' ]) [[ ' A ' ]]. LOC [ ' index column c ' ] .loc [ ' index column value d ' ]

 

Guess you like

Origin www.cnblogs.com/wt7018/p/11976074.html