Using regex for generating generic column names by
fernando_lopezr
New Altair Community Member
Hi everyone, I am trying to make a join on two tables that share not only Key attributes but column names, e.g 1960, 1961..., 2010 (although column values differ in both tables). After doing the join I got a table with duplicate column names, but different data. I want to name one set o these columns as p1960, p1961,...p2010 letting the other as is. I have tried the tool Replace by Generic name and put this regex in the generic name field p\b(19[6-8][0-9]|199[0-9]|200[0-9]|201[0-7])\b but It didn't work. Any help is appreciated.
Thanks!
Thanks!
0
Best Answer
-
I think you have overcomplicated this.
You just need to set the capture group to whatever the existing attribute name is and then replace with p plus the original capture group. So in the Rename by Replacing operator, you set the "replace what" to (.+) and then "replace with" to p$1 and it should work fine. Note that you may need to filter for only the attributes you want to do this for if there are other attributes in the dataset that you don't want to rename in that fashion, but you can do that in the same operator in the first parameter by just selecting the attributes using the regex for 4 sequential digits which is [0-9]{4}1
Answers
-
I think you have overcomplicated this.
You just need to set the capture group to whatever the existing attribute name is and then replace with p plus the original capture group. So in the Rename by Replacing operator, you set the "replace what" to (.+) and then "replace with" to p$1 and it should work fine. Note that you may need to filter for only the attributes you want to do this for if there are other attributes in the dataset that you don't want to rename in that fashion, but you can do that in the same operator in the first parameter by just selecting the attributes using the regex for 4 sequential digits which is [0-9]{4}1 -
Thanks a lot!, It works0