Split data frame string column into multiple columns

I’d like to take data of the form before = data.frame(attr = c(1,30,4,6), type=c(‘foo_and_bar’,’foo_and_bar_2′)) attr type 1 1 foo_and_bar 2 30 foo_and_bar_2 3 4 foo_and_bar 4 6 foo_and_bar_2 and use split() on the column “type” from above to get something like this: attr type_1 type_2 1 1 foo bar 2 30 foo bar_2 3 4 … Read more

Splitting on last delimiter in Python string?

What’s the recommended Python idiom for splitting a string on the last occurrence of the delimiter in the string? example: # instead of regular split >> s = “a,b,c,d” >> s.split(“,”) >> [‘a’, ‘b’, ‘c’, ‘d’] # ..split only on last occurrence of ‘,’ in string: >>> s.mysplit(s, -1) >>> [‘a,b,c’, ‘d’] mysplit takes a … Read more

Java String split removed empty values

I am trying to split the Value using a separator. But I am finding the surprising results String data = “5|6|7||8|9||”; String[] split = data.split(“\\|”); System.out.println(split.length); I am expecting to get 8 values. [5,6,7,EMPTY,8,9,EMPTY,EMPTY] But I am getting only 6 values. Any idea and how to fix. No matter EMPTY value comes at anyplace, it … Read more