8. 使索引有意义

  1. # set_index()给行索引命名
  2. In[83]: movie = pd.read_csv('data/movie.csv')
  3. In[84]: movie.shape
  4. Out[84]: (4916, 28)
  5. In[85]: movie2 = movie.set_index('movie_title')
  6. movie2
  7. Out[85]:

8. 使索引有意义 - 图1

  1. # 通过index_col参数命名
  2. In[86]: pd.read_csv('data/movie.csv', index_col='movie_title')
  3. Out[86]:

8. 使索引有意义 - 图2

更多

  1. # 复原索引
  2. In[87]: movie2.reset_index()