First page Back Continue Last page Overview Graphics

Rearrange The Ordering of Columns

We can see that an index (0,1,2, ...) has been automatically assigned to the DataFrame. We can also assign a custom index to the DataFrame object:

ordinals = ["first", "second",

"third", "fourth",

"fifth", "sixth",

"seventh", "eigth",

"ninth", "tenth",

"eleventh", "twelvth",

"thirteenth"]

city_frame = pd.DataFrame(cities,

columns=["name",

"country", "population"],

index=ordinals)

print(city_frame)