1. 获取行列索引
Example
df = pd.DataFrame([('bird', 389.0),
('bird', 24.0),
('mammal', 80.5),
('mammal', np.nan)],
index=['falcon', 'parrot', 'lion', 'monkey'],
columns=('class', 'max_speed'))
-
获取行索引
df.index
output
Index([‘falcon’, ‘parrot’, ‘lion’, ‘monkey’], dtype=‘object’)
-
获取列索引
df.columns
output
Index([‘class’, ‘max_speed’], dtype=‘object’)