# 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 import pandas as pd # Create dictionary my_dict with three key:value pairs: my_dict my_dict = {'country':['United States', 'Australia', 'Japan', 'India', 'Russia', 'Morocco', 'Egypt'], 'drives_right':[True, False, False, False, True, True, True], 'cars_per_cap':[809, 731, 588, 18, 200, 70, 45]} # Build a DataFrame cars from my_dict: cars cars = pd.DataFrame(my_dict) # Print cars print(cars) #Now this is indexed beautiful arrangement of data import pandas as pd # Build cars DataFrame 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] cars_dict = { 'country':names, 'drives_right':dr, 'cars_per_cap':cpc } cars = pd.DataFrame(cars_dict) print(cars) # Definition of row_labels row_labels = ['US', 'AUS', 'JPN', 'IN', 'RU', 'MOR', 'EG'] # Specify row labels of cars cars.index = row_labels # Print cars again print(cars)
Preview:
downloadDownload PNG
downloadDownload JPEG
downloadDownload SVG
Tip: You can change the style, width & colours of the snippet with the inspect tool before clicking Download!
Click to optimize width for Twitter