If you want to change the index, use either reindexor assign directly to the index:
In [5]:
data1=pd.DataFrame({'AAA':[4,5,6,7],'BBB':[10,20,30,40],'CCC':[100,50,-30,-50]})
print(data1)
df=pd.DataFrame(data=data1)
df.index = ['a','b','c','d']
df
AAA BBB CCC
0 4 10 100
1 5 20 50
2 6 30 -30
3 7 40 -50
Out[5]:
AAA BBB CCC
a 4 10 100
b 5 20 50
c 6 30 -30
d 7 40 -50
, , , :
In [7]:
df=pd.DataFrame(data=data1.values,index=(['a','b','c','d']))
df
Out[7]:
0 1 2
a 4 10 100
b 5 20 50
c 6 30 -30
d 7 40 -50
, , df, df
, df, , :
In [46]:
data1 = pd.DataFrame({'AAA':[4,5,6,7],'BBB':[10,20,30,40],'CCC':[100,50,-30,-50]})
data1.reindex_axis(list('abcd'))
Out[46]:
AAA BBB CCC
a NaN NaN NaN
b NaN NaN NaN
c NaN NaN NaN
d NaN NaN NaN
, df, , BlockManager df:
, , frame.py:
if isinstance(data, BlockManager):
mgr = self._init_mgr(data, axes=dict(index=index, columns=columns),
dtype=dtype, copy=copy)
generic.py:
119 def _init_mgr(self, mgr, axes=None, dtype=None, copy=False):
120 """ passed a manager and a axes dict """
121 for a, axe in axes.items():
122 if axe is not None:
123 mgr = mgr.reindex_axis(
124 -> axe, axis=self._get_block_manager_axis(a), copy=False)
issue
, , , df, @Jeff
, / .
.