Create and set an element of a Pandas DataFrame to a list

后端 未结 3 1623
野的像风
野的像风 2021-01-13 01:14

I have a Pandas DataFrame that I\'m creating row-by-row (I know, I know, it\'s not Pandorable/Pythonic..). I\'m creating elements using .loc like so



        
3条回答
  •  庸人自扰
    2021-01-13 02:17

    The answer by MishaTeplitskiy works when the index label is 0. More generally, if you want to assign an array x to an element of a DataFrame df with row r and column c, you can use:

    df.loc[[r], c] = pd.Series([x], index = [r])
    

提交回复
热议问题