Set value for particular cell in pandas DataFrame using index

后端 未结 20 2021
野趣味
野趣味 2020-11-22 05:45

I\'ve created a Pandas DataFrame

df = DataFrame(index=[\'A\',\'B\',\'C\'], columns=[\'x\',\'y\'])

and got this

    x    y
A  NaN         


        
20条回答
  •  面向向阳花
    2020-11-22 06:47

    You can also use a conditional lookup using .loc as seen here:

    df.loc[df[] == , []] = 
    

    where is the column you want to check the variable against and is the column you want to add to (can be a new column or one that already exists). is the value you want to add to that column/row.

    This example doesn't work precisely with the question at hand, but it might be useful for someone wants to add a specific value based on a condition.

提交回复
热议问题