After Pandas Dataframe pd.concat I get NaNs

前端 未结 1 559
失恋的感觉
失恋的感觉 2021-02-06 13:39

I have three pandas df one of them has been \'row\'-shifted and the first element is empty. When I concatenate the three df to obtain a single 3-column dataframe I get all NaN i

1条回答
  •  隐瞒了意图╮
    2021-02-06 14:06

    In [2]: index = pd.DatetimeIndex(['2010-12-31', '2011-01-01', '2011-01-02'])
    
    In [3]: df1 = pd.DataFrame({'S':[True,False,False]}, index=index)
    
    In [4]: df2 = pd.DataFrame({'P':['','On','On']}, index=index)
    
    In [5]: df3 = pd.DataFrame({'C':['On','On','On']}, index=index)
    

    If your DataFrames are defined as above, then pd.concat with axis=1 should work:

    In [7]: pd.concat([df1,df2,df3], axis=1)
    Out[7]: 
                    S   P   C
    2010-12-31   True      On
    2011-01-01  False  On  On
    2011-01-02  False  On  On
    
    [3 rows x 3 columns]
    

    0 讨论(0)
提交回复
热议问题