Skip to content
Advertisement

Tag: regex

Replacing values using dictionary

What are the reasons why are regex replacment doesn’t work? I have tried ensuring no excess spaces. When I do df.loc[df[‘column’]==”and another reason with her”] nothing has changed. Answer Please use df.replace(regex=dict)

Extracting various variables from a file in Python

I have a file that looks like I would like to extract the values of “A”, “B”, “C”, the last value of “E. E.” and all values of “a_{i}” and “a_{i}a_{j}”. To get A, B, and C, I have used this code as I know exactly the lines’ numbers How can I extract the rest? For the last “E.E.” the

Remove words when match with first 3 or 4 characters

I need to remove the words in the sentance which starts with sst or abc I have a sentence in this way: I need to remove those words from the above two sentences. I tried with regex sub module but not working It is removing the word when there is a space only Answer You can use See the regex

Repeat pattern using python regex

Well, I’m cleaning a dataset, using Pandas. I have a column called “Country”, where different rows could have numbers or other information into parenthesis and I have to remove them, for example: Australia1, PerĂº (country), 3Costa Rica, etc. To do this, I’m getting the column and I make a mapping over it. But I have a problem with this regex,

Issue with conversion of text data into a dataframe

I have a text file where I have several lines and between them, some data which I need to convert to the dataframe(useful data). I iterated the text file line by line and captured the useful data with the help of a regex. Something like this, The data captured look like this I thought to iterate each captured row and

How to have categorical regex groups with Python

I have a text which corresponds to a pattern can must be split into categories. I thought of using groups to capture parts of the text that correspond to a particular category patern, and then map that part to my category. Unfortunately, as far as I know group names in Python regex cannot have the same name, and I cannot

How to use regex to scrape entire sentences from fragments in python

I have a vtt file as following I want to extract the fragments from the file and merge them into sentences. The output should look something like this I am able to extract the fragments using this I am not sure how to extract entire sentences instead of fragments. Also note that this is just a sample of the vtt

Regular Expression split w/ Lookbehind loses second half

I have a string that contains a number of keywords. I would like to split the string into a list of those keywords (but keep the keywords because they identify what the following data means) Take the following string for example: the important keywords are “ttyp”, “pfil”, “tsng”, “tart”. I would like to split the file so the output looks:

Advertisement