Add numpy array as column to Pandas data frame

前端 未结 5 1355
离开以前
离开以前 2020-12-02 16:30

I have a Pandas data frame object of shape (X,Y) that looks like this:

[[1, 2, 3],
[4, 5, 6],
[7, 8, 9]]

and a numpy sparse matrix (CSC) of

5条回答
  •  甜味超标
    2020-12-02 16:55

    df = pd.DataFrame(np.arange(1,10).reshape(3,3))
    df['newcol'] = pd.Series(your_2d_numpy_array)
    

提交回复
热议问题