KeyError while setting index of Dataframe
I have a dataframe port
and I am trying to set its index as follows. However, I am getting an error KeyError: 0
on the line port = port.set_index(l)
and am not sure why this is the case. It currently port
has a row index.
port
as follows:
Date ^GSPC AAPL IBM dell wmt
2013-10-29 1771.949951 71.290195 174.302136 13.86000 73.328899
2013-10-28 1762.109985 73.111495 169.736908 13.83000 73.405027
Code:
l = [0]*port.shape[0] count = 0 for i,j in enumerate(l): l[i] = count count += 1 port = port.set_index(l)
thank
+3
source to share
1 answer