Assigning multiple column values in a single row of pandas DataFrame, in one line

前端 未结 1 1014
心在旅途
心在旅途 2020-12-15 20:42

I\'m trying to Assign multiple values to a single row in a DataFrame and I need the correct syntax.

See the code below.

import pandas as pd

df = p         


        
相关标签:
1条回答
  • 2020-12-15 21:22

    Use loc (and avoid chaining):

    In [11]: df.loc[3] = ['V1', 4.3, 2.2, 2.2, 20.2]
    

    This ensures the assigning is done inplace on the DataFrame, rather than on a copy (and garbage collected).

    You can specify only certain columns:

     In [12]: df.loc[3, list('ABCDE')] = ['V1', 4.3, 2.2, 2.2, 20.2]
    
    0 讨论(0)
提交回复
热议问题