Jul-11-2020, 09:26 PM
import pandas as pd
import numpy as np
index = [('California', 2000), ('California', 2010),
('New York', 2000), ('New York', 2010),
('Texas', 2000), ('Texas', 2010)]
populations = [33871648, 37253956,
18976457, 19378102,
20851820, 25145561]
index = pd.MultiIndex.from_tuples(index)
print(index)
pop = populations.reindex(index)Error:AttributeError Traceback (most recent call last)
in
9 index = pd.MultiIndex.from_tuples(index)
10 print(index)
---> 11 pop = populations.reindex(index)
12 #pop_df = pop.unstack()
AttributeError: 'list' object has no attribute 'reindex'I'm trying to reindex to get something like thisOutput:California 2000 33871648
2010 37253956
New York 2000 18976457
2010 19378102
Texas 2000 20851820
2010 25145561Any idea how to solve this error? In my e-book this code works.
