DataFrame filter rows by value



examples/pandas/planets_filter_row_by_value.py
import sys
import pandas as pd

filename = "planets.csv"
if len(sys.argv) == 2:
    filename = sys.argv[1]

df = pd.read_csv(filename)


planet_selector = (df['Planet name'] == 'Earth')
print(planet_selector)
print()

planets = df[ planet_selector ]
print(planets)

0     False
1     False
2      True
3     False
4     False
5     False
6     False
7     False
8     False
9     False
10    False
Name: Planet name, dtype: bool

  Planet name  Distance (AU)  Mass
2       Earth            1.0   1.0