replace

Conditionally replace values of multiple columns, from values of other multiple columns

心已入冬 提交于 2021-02-04 06:52:59
问题 Suppose I have this dataset: set.seed (1234); data.frame(cbind(a=rep(c("si","no"),30),b=rnorm(60)), c=rep(c("d","e","f"),20)) %>% head() Then I want to add many columns (in this example I only added two), to identify distinct cases between each group (in this case, column "a"). set.seed(1234); data.frame(cbind(a=rep(c("si","no"),30),b=rnorm(60)),c=rep(c("d","e","f"),20)) %>% group_by(a) %>% dplyr::mutate_at(vars(c(b,c)), .funs= list(dups_hash_ing= ~n_distinct(.))) This code leaves the

Change values in a column from a list

柔情痞子 提交于 2021-01-30 09:08:50
问题 I've got a dataframe with my index 'Country' I want to change the name of multiple countries, I have the old/new values in a dictionary, like below: I tried splitting the values in a from list and to list, and that wouldn't work either. The code doesn't error, but the values in my dataframe haven't changed. `import pandas as pd import numpy as np energy = (pd.read_excel('Energy Indicators.xls', skiprows=17, skip_footer=38)) energy = (energy.drop(energy.columns[[0, 1]], axis=1)) energy.columns

Change values in a column from a list

旧街凉风 提交于 2021-01-30 09:05:32
问题 I've got a dataframe with my index 'Country' I want to change the name of multiple countries, I have the old/new values in a dictionary, like below: I tried splitting the values in a from list and to list, and that wouldn't work either. The code doesn't error, but the values in my dataframe haven't changed. `import pandas as pd import numpy as np energy = (pd.read_excel('Energy Indicators.xls', skiprows=17, skip_footer=38)) energy = (energy.drop(energy.columns[[0, 1]], axis=1)) energy.columns

How to recover SVN Revision History after a “Replace” action on a File

帅比萌擦擦* 提交于 2021-01-29 20:18:40
问题 I have completed a "replacing" action on a single file and committed it. See the TortoiseSVN "Show Log" window below. It now has no revision history. Forgive my novice level and unfamiliarity with SVN and TortoiseSVN, but I am in need of layman's instructions for restoring the revision history of a single file after I performed and committed the "replacement" action on it. I have tried to checkout an older revision of that file, but the revision history is not recovered. Thank you in advance

How to replace plus (+) signs with spaces ( ) in GET parameters with javascript

人走茶凉 提交于 2021-01-29 18:39:32
问题 I get users redirected to my site with GET parameters like this: www.example.com/?email=mail@mail.com&vorname=name1+name2 I use javascript to populate my texfields (newsletter subscription) like this: function getUrlVars() { var vars = {}; var parts = window.location.href.replace(/[?&]+([^=&]+)=([^&]*)/gi, function(m,key,value) { vars[key] = value; }); return vars; } function getUrlParam(parameter, defaultvalue){ var urlparameter = defaultvalue; if(window.location.href.indexOf(parameter) > -1

How to replace plus (+) signs with spaces ( ) in GET parameters with javascript

心不动则不痛 提交于 2021-01-29 12:56:54
问题 I get users redirected to my site with GET parameters like this: www.example.com/?email=mail@mail.com&vorname=name1+name2 I use javascript to populate my texfields (newsletter subscription) like this: function getUrlVars() { var vars = {}; var parts = window.location.href.replace(/[?&]+([^=&]+)=([^&]*)/gi, function(m,key,value) { vars[key] = value; }); return vars; } function getUrlParam(parameter, defaultvalue){ var urlparameter = defaultvalue; if(window.location.href.indexOf(parameter) > -1

Replace each item differently, regex c++

坚强是说给别人听的谎言 提交于 2021-01-29 11:50:40
问题 I have a long string and I need to convert digits to words (ex. 5 to five). Can I do this with a regex? I tried using regex_replace , but this changed all the numbers to the one that was found first (ex. it converted "5 10 1 0" to "five five five five", but I need "five ten one zero"). This was my attempt: string text ="a lot of text"; regex pattern("(\\d)+"); smatch result; int x; string buffer; while (regex_search(text, result, pattern)) { buffer = result[0]; x = atoi(buffer.c_str());

python: better way to handle case sensitivities with df.replace

让人想犯罪 __ 提交于 2021-01-29 11:29:38
问题 I have the following code to replace text in my dataframe - dfMSR. oldtxts = ['NA', 'na'] newtxt = 'N/A' for oldtxt in oldtxts: if oldtxt in dfMSR.values: dfMSR = dfMSR.replace(oldtxt, newtxt, regex=True) else: print("\nNo {oldtxt} in Dataframe") Is there a better way to replace all cases scenarios without spelling them out or changing the case of all text in the dataframe to upper or lower? In the above code if the user wrote 'Na', it wouldn't be replaced as I haven't included it in oldtxts.

Oracle - replace string by appearance

走远了吗. 提交于 2021-01-29 05:37:19
问题 I have an interesting issue here, if you could share your thoughts ... I changed data a bit, but structure is same create table TestReplace (Description varchar2(500), ParamValue1 number, ParamValue2 number, ParamValue3 number); insert into TestReplace (Description) values ('This sentence has no parameteres, and it should be shown like this'); insert into TestReplace (Description, ParamValue1) values ('This sentence has only one parametere, and it should be shown right here {param} with rest

PowerShell - Find and replace multiple patterns to anonymize file

↘锁芯ラ 提交于 2021-01-29 04:45:56
问题 I need you help. I have a log.txt file with various data in it which I have to anonymize. I would like to retrieve all these "strings" matching a predefined patterns, and replace these by another values for each of them. What is important is that each new string from the same pattern (and with different value from the previous) should be replaced by the predefined value increased by +1 (e.g. "orderID = 123ABC" becomes "orderID = order1" and "orderID=456ABC" becomes "orderID=order2"). The