Python Forum
Problem in Regex Expression - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: General Coding Help (https://python-forum.io/forum-8.html)
+--- Thread: Problem in Regex Expression (/thread-35091.html)



Problem in Regex Expression - shantanu97 - Sep-28-2021

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)



RE: Problem in Regex Expression - bowlofred - Sep-28-2021

Is there something wrong? Your output seems to match your description.


RE: Problem in Regex Expression - shantanu97 - Sep-28-2021

(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.