2. 层次化索引(Python)

# 将类日期转成datetime
# 按照先个体再时间的顺序排序
# 将个体和时间层次化索引

dataset['TradeMonth'] = pd.to_datetime(dataset['TradeMonth']) 
dataset.sort_values(by=['Nnindcd','TradeMonth'],inplace =True) 
dataset.set_index(['Nnindcd','TradeMonth'],inplace = True)
dataset

你可能感兴趣的:(2. 层次化索引(Python))