Python Forum

Full Version: Problem in Regex Expression
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
I have file where I want to replace the particular row when a particular thing(string) matches with semicolon. If Equipment onsite is null/nothing then replace with semicolon, otherwise if there is anything after equipment onsite, I wanted to keep as it is. Check the image how the output look likes. any help what wrong in regular expression.

import pandas as pd 
import re

data = pd.read_csv("TestEquipmentOnsite.csv", header=0) 

data = data.replace(r",Equipment onsite=", ";", regex=True) 
print(data)
Is there something wrong? Your output seems to match your description.
(Sep-28-2021, 03:36 AM)bowlofred Wrote: [ -> ]Is there something wrong? Your output seems to match your description.

I attach image how I wanted the output to look like. If you run the code, the output look like quite different what I wanted.