Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Pandas read CSV set index column

import pandas as pd

df = pd.read_csv('planets.csv', index_col='Planet name')
print(df.head(2))

Output:

             Distance (AU)   Mass
Planet name                      
Mercury                0.4  0.055
Venus                  0.7  0.815