loc and iloc - part 2

PHOTO EMBED

Thu Nov 25 2021 07:45:44 GMT+0000 (Coordinated Universal Time)

Saved by @Sourabh ##dictionary ##pandas #defining_data_frame #csv #dataframe #square #bracket'

# Import cars data
import pandas as pd
cars = pd.read_csv('cars.csv', index_col = 0)

# Print out drives_right value of Morocco
print(cars.loc[['MOR', 'drives_right']])

# Print sub-DataFrame
print(cars.iloc[[4,5], [1,2]])
content_copyCOPY

loc and iloc also allow you to select both rows and columns from a DataFrame.