Home > Software engineering >  pandas filter column1 and replace its values in column2
pandas filter column1 and replace its values in column2

Time:07-08

In the column 1 I want to filter all users looking for specific one and than replace value for this specific user in different column.

So in table 1 is what I got and table 2 what output I need: example

Based on these tables: Filter all XXXX in User column and replace their status for Expired

For the past few hours I have been trying to change my code multiple times but it seems like nothing fully works.

CodePudding user response:

Can you do a loc on your dataframe? for example:

df.loc[df["User"] == "XXXX", "Status"] = "Expired"

CodePudding user response:

df.loc[ your_condition, 'column1' ] = df.loc[ your_condition, 'column2' ]
  • Related