import numpy as npfrom pandas import Series, DataFrame###重命名轴索引data = DataFrame(np.arange(12).reshape((3, 4)), index=['Ohio', 'Colorado', 'New York'], columns=['one', 'two', 'three', 'four']) print( data.index.map(str.upper) ) #['OHIO' 'COLORADO' 'NEW YORK'] data.index = data.index.map(str.upper)print( data )''' one two three fourOHIO 0 1 2 3COLORADO 4 5 6 7NEW YORK 8 9 10 11''' data_2 = data.rename(index=str.title, columns=str.upper)print( data_2 )''' ONE TWO THREE FOUROhio 0 1 2 3Colorado 4 5 6 7New York 8 9 10 11'''data_3 = data.rename(index={'OHIO': 'INDIANA'}, columns={'three': 'peekaboo'})print( data_3 )''' one two peekaboo fourINDIANA 0 1 2 3COLORADO 4 5 6 7NEW YORK 8 9 10 11''' # 总是返回DataFrame的引用_ = data.rename(index={'OHIO': 'INDIANA'}, inplace=True)print( _ ) # None