python - How can i update pandas dataframe columns based on index -


in pandas have dataframe:

df1 = pd.dataframe({'type':['application','application','hardware'],                     'category': ['none','none','hardware']}) 

i have following index retrieve rows type contains "application" , category contains 'none'.

df1[df1['type'].str.contains('application') & df1['category'].str.contains('none')]  category    type 0   none    application 1   none    application 

i update column category such value 'some new value' each row.

i have tried same following loc index no success

df1[df1.loc[:,'type'].str.contains('application') \   & df1.loc[:,'category'].str.contains('none')] 

thanks.

are looking this?

df1.loc[(df1['type'] == 'application') & (df1['category'] == 'none'), 'category'] = 'new category'       category        type 0   new category    application 1   new category    application 2   hardware        hardware 

Comments

Popular posts from this blog

Is there a better way to structure post methods in Class Based Views -

performance - Why is XCHG reg, reg a 3 micro-op instruction on modern Intel architectures? -

jquery - Responsive Navbar with Sub Navbar -