BUG: DataFrame constructor incorrect with Series input depending on name · Issue #9232 · pandas-dev/pandas (original) (raw)
DataFrame constructor example:
In [55]: x = pd.Series(range(5), name=1)
In [56]: y = pd.Series(range(5), name=0)
In [57]: pd.DataFrame(x, columns=[0]) Out[57]: Empty DataFrame Columns: [0] Index: []
In [58]: pd.DataFrame(x, columns=[1]) Out[58]: 1 0 0 1 1 2 2 3 3 4 4
and for y, the name and columns don't have to match for it to construct.
In [59]: pd.DataFrame(y, columns=[0])
Out[59]:
0
0 0
1 1
2 2
3 3
4 4
In [60]: pd.DataFrame(y, columns=[1])
Out[60]:
1
0 0
1 1
2 2
3 3
4 4
Using Pandas 0.15.2-1. After renaming a column in a dataframe, a .join operation fails.
import numpy as np,pandas as pd df1=pd.DataFrame(range(1,1001)).rename(columns={0:1}) a=np.log(df1[1]) df2=df1.join(pd.DataFrame(a,columns=[0]))
The second column contains all NaN, instead of the values from a. The same can be accomplished by other means, but I believe the above should work. For example, the following works:
df1=pd.DataFrame(range(1,1001)) a=np.log(df1[0]) df2=df1.join(pd.DataFrame(a,columns=[2]))