Planets DataFrame select rows and columns
examples/pandas/planets_rows_columns.py
import sys import pandas as pd filename = "planets.csv" if len(sys.argv) == 2: filename = sys.argv[1] df = pd.read_csv(filename) small = df[2:5][['Distance (AU)', 'Planet name']] print(type(small)) print(small) print() other = df.iloc[3:6][['Distance (AU)', 'Planet name']] print(type(other)) print(other) print()
<class 'pandas.core.frame.DataFrame'> Distance (AU) Planet name 2 1.00 Earth 3 1.50 Mars 4 2.77 Ceres <class 'pandas.core.frame.DataFrame'> Distance (AU) Planet name 3 1.50 Mars 4 2.77 Ceres 5 5.20 Jupiter