Import pandas Library
import pandas as pd
Create 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]
Create a new Dictionary and input the List into the Dictionary
cars_dict = { 'country':names, 'drives_right':dr, 'cars_per_cap':cpc }
Convert the Dictionary into Pandas DataFrame
cars = pd.DataFrame(cars_dict)
Print Cars
print(cars)
country drives_right cars_per_cap 0 United States True 809 1 Australia False 731 2 Japan False 588 3 India False 18 4 Russia True 200 5 Morocco True 70 6 Egypt True 45
Replace Row Index with Row Labels
row_labels = ['US', 'AUS', 'JPN', 'IN', 'RU', 'MOR', 'EG']
cars.index = row_labels
print(cars)
country drives_right cars_per_cap US United States True 809 AUS Australia False 731 JPN Japan False 588 IN India False 18 RU Russia True 200 MOR Morocco True 70 EG Egypt True 45