You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Whilst answering this SO question I discovered that the DataFrame constructor is ignoring the fact that I'm passing an index explicitly resulting in a df with all NaNs:
In [6]:
df = pd.DataFrame({'AAA':[4,5,6,7],'BBB':[10,20,30,40],'CCC':[100,50,-30,-50]})
df1 = pd.DataFrame(data=df,index=(['a','b','c','d']))
df1
Out[6]:
AAA BBB CCC
a NaN NaN NaN
b NaN NaN NaN
c NaN NaN NaN
d NaN NaN NaN
Stepping through the code I see that it reaches here in frame.py:
if isinstance(data, BlockManager):
mgr = self._init_mgr(data, axes=dict(index=index, columns=columns),
dtype=dtype, copy=copy)
and then ends up here in 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)
The behaviour can be reproduced simply like this:
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
The text was updated successfully, but these errors were encountered:
Whilst answering this SO question I discovered that the DataFrame constructor is ignoring the fact that I'm passing an index explicitly resulting in a df with all NaNs:
Stepping through the code I see that it reaches here in frame.py:
and then ends up here in generic.py:
The behaviour can be reproduced simply like this:
The text was updated successfully, but these errors were encountered: