Add column in dataframe from list

前端 未结 5 749
死守一世寂寞
死守一世寂寞 2020-12-04 07:16

I have a dataframe with some columns like this:

A   B   C  
0   
4
5
6
7
7
6
5

The possible range of values in A are only from 0 to 7

5条回答
  •  我在风中等你
    2020-12-04 07:58

    Just assign the list directly:

    df['new_col'] = mylist
    

    Alternative
    Convert the list to a series or array and then assign:

    se = pd.Series(mylist)
    df['new_col'] = se.values
    

    or

    df['new_col'] = np.array(mylist)
    

提交回复
热议问题