0

I have a pandas dataframe that has 4 columns. Let's say: Test_Name, Runtime, Memory, Location

I want to find all the Test_Name = 'my_test' and replace the Location value with 'my_test_location'

So, effectively, it should search for all the test_names that match my search query and in those rows, replace the location field with the string i'm giving as input.

I know i can do this by iterating over every row. I want to know if an inbuilt function exists that can do this.

Any help is appreciated.

Original Dataframe:

enter image description here

Find all testcases with name = 'peter' and replace location field with '/work/peter'

Final Dataframe:

enter image description here

lonely
  • 681
  • 1
  • 7
  • 10

1 Answers1

1

Dude try .loc and .iloc

df.loc[df.Test_Name == "my_test", "Location"] = "my_test_location"

Adding doc for loc

Shivam Kotwalia
  • 1,419
  • 2
  • 15
  • 20