replace

Replace space in between double quote to underscore

Replace space in between double quote to underscore Question: I want to replace a space to underscore, if the space is in between double quotes. Example: given = ‘hello "welcome to" python "blog"’ expected = ‘hello "welcome_to" python "blog"’ My actual string is in SQL code and I need to transform it to use underscore …

Total answers: 3

Is there a cleaner way to replace characters in a text file?

Is there a cleaner way to replace characters in a text file? Question: i am trying to replace characters in a text file, the code works but it just seems too long. I was wondering if there is a different way to do this? (It is a good way for me to learn a better …

Total answers: 1

Values replacement in python pandas

Values replacement in python pandas Question: I need to replace each cell containing values like number1(number2) with number2 (the value inside the parenthesis). For example: 56(3) -> 3, 33(5) -> 5 These values can appear in different columns. The problem is that with pandas function df.replace(to_replace=…, value=…) i cannot use as value something that depends …

Total answers: 1

Python: how to form the correct list

Python: how to form the correct list Question: This is my data looks like my_list = [(‘Australia’,), (‘Europe’,)] I need to remove the comma "," after every element. new_list = [(‘Australia’), (‘Europe’)] I can achieve this using a loop and extracting one element at a time and replacing it. Is there a better way to …

Total answers: 2

Using Pandas to dynamically replace values found in other columns

Using Pandas to dynamically replace values found in other columns Question: I have a dataset looks like this: Car Make Model Engine Toyota Rav 4 8cyl6L Toyota 8cyl6L Mitsubishi Eclipse 2.1T Mitsubishi 2.1T Monster Gravedigger 25Lsc Monster 25Lsc The data was clearly concatenated from Make + Model + Engine at some point but the car …

Total answers: 2

Python | How do I swap two unknown words in an unknown string?

Python | How do I swap two unknown words in an unknown string? Question: I cannot find how to swap two words in a string using Python, without using any external/imported functions. What I have is a string that I get from a text document. For example the string is: line = "Welcome to your …

Total answers: 2