how to change the column value based on other column value in data frame?

Shivam

I am trying to change one column value based on other columns value. Can you please help me how to do this?

Example:

priority     comb_fld_order       start_bracs     end_bracs
1                                   (
1.1           
2.3           1                     (
2.3.1         1                                      )
3.7                                                  )

Expected Output:

priority     comb_fld_order       start_bracs     end_bracs
1                                   
1.1           
2.3           1                     (
2.3.1         1                                      )
3.7    

Means if comb_fld_order is null then we should to remove brackets from start_bracs and end_bracs column.

Shubham Sharma

You can create a boolean mask using Series.eq, then use Series.where to replace the values based on condition:

m = df['comb_fld_order'].eq('')
df['start_bracs'] = df['start_bracs'].where(~m, '')
df['end_bracs'] = df['end_bracs'].where(~m, '')

Result:

# print(df)

  priority comb_fld_order start_bracs end_bracs
0        1                                     
1      1.1                                     
2      2.3              1           (          
3    2.3.1              1                     )
4      3.7                                     

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

How to assign a value to a column based on value in other column in R data frame or data table

How to extract value of column based on value change in other column python

How to change column element based on value change in other column in R

How to change value in one data frame based on the other data frame?

Replace column value in a data frame based on other columns

Change Column Value Based on Other Column by Group

Change column class based on other data frame

How to select row value from given columns based on comparison of other column values in Pandas data frame?

Change week of year value based on conditional data in other column in R

MYSQL query change column value based on the other column value

Change value of column of Dataframe based on value of other column

The matching columns from a data frame based on value in a column from other data Frame

how to filter a data frame based on a column value (country) in pandas

Aggregate data frame based on column value in R

Highlight row in a data frame based on a column value?

How to change value in column based on the other table that is not related

How to change a value based on a condition in other column in R?

Pandas change value based on other column values

Delete last element from lists in column of data frame based on other column value

Creating a column in data frame that indicate if value in other column is consecutive

Create new column if value appears in column of other data frame

How to create new pandas column based on other column of data frame?

How to update multiple columns in window frame based on other column value on same window frame

Change value based on column

Append column to data frame with text based on another column value

Sort data frame based on the value of a column and the length of a list in another column

Create new column based on a value of another column in a data-frame

How to fill column based on previous value + value other column in R

How to replace value of Pandas column based on value in other column