Set value to an entire column of a pandas dataframe

前端 未结 8 2052
甜味超标
甜味超标 2020-12-13 05:54

I\'m trying to set the entire column of a dataframe to a specific value.

In  [1]: df
Out [1]: 
     issueid   industry
0        001        xxx
1        002           


        
相关标签:
8条回答
  • 2020-12-13 06:43

    This provides you with the possibility of adding conditions on the rows and then change all the cells of a specific column corresponding to those rows:

    df.loc[(df['issueid'] == '001'), 'industry'] = str('yyy')
    
    0 讨论(0)
  • 2020-12-13 06:44
    df.loc[:,'industry'] = 'yyy'
    

    This does the magic. You are to add '.loc' with ':' for all rows. Hope it helps

    0 讨论(0)
提交回复
热议问题