replace

Conditionally replace values in one column with values from another column using dplyr [duplicate]

流过昼夜 提交于 2021-01-21 07:12:18
问题 This question already has an answer here : Change value of variable with dplyr [duplicate] (1 answer) Closed 2 years ago . I want to replace the values in one column that match a certain condition with values in that same row from a different column. Consider this example: library(tidyverse) data <- tribble( ~X25, ~Other, "a", NA, "b", NA, "Other", "c", "Other", "d" ) View(data) # Works to change values in X25 within(data, { X25 <- ifelse(X25 == "Other", Other, X25) }) # Changes values in X25

Beautiful Soup 4: How to replace a tag with text and another tag?

三世轮回 提交于 2021-01-21 03:58:06
问题 I want to replace a tag with another tag and put the contents of the old tag before the new one. For example: I want to change this: <html> <body> <p>This is the <span id="1">first</span> paragraph</p> <p>This is the <span id="2">second</span> paragraph</p> </body> </html> into this: <html> <body> <p>This is the first<sup>1</sup> paragraph</p> <p>This is the second<sup>2</sup> paragraph</p> </body> </html> I can easily find all spans with find_all() , get the number from the id attribute and

Perform a non-regex search/replace in vim

女生的网名这么多〃 提交于 2021-01-20 15:19:40
问题 When doing search/replace in vim, I almost never need to use regex, so it's a pain to constantly be escaping everything, Is there a way to make it default to not using regex or is there an alternative command to accomplish this? As an example, if I want to replace < with < , I'd like to just be able to type s/</</g instead of s/\</\&lt\;/g 回答1: For the :s command there is a shortcut to disable or force magic. To turn off magic use :sno like: :sno/search_string/replace_string/g Found here:

Find and replace regex in Intellij, but keep some of the matched regex?

99封情书 提交于 2021-01-18 02:48:45
问题 I changed an array to a list, so I want to change all instances of myObject[index] to myObject.get(index) where index is different integers. I can find these instances by doing `myObject\[.*\]` However, I am not sure what I should put in the replace line - I don't know how to make it keep the index values. 回答1: Use the following regex replacement: Find : myObject\[(.*?)\] Replace : myObject.get($1) If the index is an integer, you may replace (.*?) with (\d+) . The pair of unescaped

Is there any other way to remove all whitespaces in a string?

落花浮王杯 提交于 2021-01-13 09:27:26
问题 I have a programming homework. It says that I need to reverse the string first, then change it to uppercase and then remove all the whitespaces. I actually did it, but our professor didn't say anything about using replaceAll() method. Is there any other way to do it beside replaceAll() ? Here is my code: public static void main(String[] args) { String line = "the quick brown fox"; String reverse = ""; for (int i = line.length() - 1; i >= 0; i--) { reverse = reverse + line.charAt(i); } System

Import csv: remove filename from column names in first row

强颜欢笑 提交于 2021-01-05 07:19:45
问题 I am using Python 3.5. I have several csv files: The csv files are named according to a fixed structure. They have a fixed prefix (always the same) plus a varying filename part: 099_2019_01_01_filename1.csv 099_2019_01_01_filename2.csv My original csv files look like this: filename1-Streetname filename1-ZIPCODE TEXT TEXT TEXT TEXT TEXT TEXT TEXT TEXT TEXT TEXT TEXT TEXT Street1 2012932 Street2 3023923 filename2-Name filename2-Phone TEXT TEXT TEXT TEXT TEXT TEXT TEXT TEXT TEXT TEXT TEXT TEXT

.NET Core - Changing dependency in Controller

徘徊边缘 提交于 2021-01-04 10:34:45
问题 I am working on an web application (.net core 2.2) and trying to replace existing dependency over an querystring parameter in controller. I know, it is possible to replace dependency inside Startup.cs (ConfigureServices(IServiceCollection services) method). But problem is I cant access "IServiceCollection " in controller. Do you guys have an idea how to achive it? This is the way to replace dependency in Startup. "ServiceCollectionDescriptorExtensions" has "Replace" method. services.Replace

Replace values in DataFrame column when they start with string using lambda

不羁的心 提交于 2021-01-04 04:22:50
问题 I have a DataFrame: import pandas as pd import numpy as np x = {'Value': ['Test', 'XXX123', 'XXX456', 'Test']} df = pd.DataFrame(x) I want to replace the values starting with XXX with np.nan using lambda. I have tried many things with replace, apply and map and the best I have been able to do is False, True, True, False. The below works, but I would like to know a better way to do it and I think the apply, replace and a lambda is probably a better way to do it. df.Value.loc[df.Value.str

Replace values in DataFrame column when they start with string using lambda

為{幸葍}努か 提交于 2021-01-04 04:16:17
问题 I have a DataFrame: import pandas as pd import numpy as np x = {'Value': ['Test', 'XXX123', 'XXX456', 'Test']} df = pd.DataFrame(x) I want to replace the values starting with XXX with np.nan using lambda. I have tried many things with replace, apply and map and the best I have been able to do is False, True, True, False. The below works, but I would like to know a better way to do it and I think the apply, replace and a lambda is probably a better way to do it. df.Value.loc[df.Value.str

Replace values in DataFrame column when they start with string using lambda

人盡茶涼 提交于 2021-01-04 04:14:01
问题 I have a DataFrame: import pandas as pd import numpy as np x = {'Value': ['Test', 'XXX123', 'XXX456', 'Test']} df = pd.DataFrame(x) I want to replace the values starting with XXX with np.nan using lambda. I have tried many things with replace, apply and map and the best I have been able to do is False, True, True, False. The below works, but I would like to know a better way to do it and I think the apply, replace and a lambda is probably a better way to do it. df.Value.loc[df.Value.str