This is from DataCamp exercise and worked correctly on website as well as the PyCharm Interpreter
# Pre-defined lists
names = ['United States', 'Australia', 'Japan', 'India', 'Russia', 'Morocco', 'Egypt']
dr = [True, False, False, False, True, True, True]
cpc = [809, 731, 588, 18, 200, 70, 45]
import pandas as pd
# Create dictionary my_dict with three key:value pairs: my_dict
my_dict = {"country": names, "drives_right": dr, "cars_per_cap": cpc}
# Build a DataFrame cars from my_dict: cars
cars = pd.DataFrame(my_dict)
# Print cars
print(cars)
print("\n*Using 'loc':")
print(cars.loc[[1]])
Breaks right here
print(cars.loc[[names]])
*says 'names' not in the index
CodePudding user response:
[result 2]
p.s.
pandas loc
is primarily label based