How to split a comma-separated string?

You could do this: String str = “…”; List<String> elephantList = Arrays.asList(str.split(“,”)); Basically the .split() method will split the string according to (in this case) delimiter you are passing and will return an array of strings. However, you seem to be after a List of Strings rather than an array, so the array must be … Read more

How can I split a string into segments of n characters?

var str=”abcdefghijkl”; console.log(str.match(/.{1,3}/g)); Note: Use {1,3} instead of just {3} to include the remainder for string lengths that aren’t a multiple of 3, e.g: console.log(“abcd”.match(/.{1,3}/g)); // [“abc”, “d”] A couple more subtleties: If your string may contain newlines (which you want to count as a character rather than splitting the string), then the . won’t … Read more

Split large string in n-size chunks in JavaScript

You can do something like this: “1234567890”.match(/.{1,2}/g); // Results in: [“12”, “34”, “56”, “78”, “90”] The method will still work with strings whose size is not an exact multiple of the chunk-size: “123456789”.match(/.{1,2}/g); // Results in: [“12”, “34”, “56”, “78”, “9”] In general, for any string out of which you want to extract at-most n-sized … Read more

Split a Pandas column of lists into multiple columns

You can use the DataFrame constructor with lists created by to_list: import pandas as pd d1 = {‘teams’: [[‘SF’, ‘NYG’],[‘SF’, ‘NYG’],[‘SF’, ‘NYG’], [‘SF’, ‘NYG’],[‘SF’, ‘NYG’],[‘SF’, ‘NYG’],[‘SF’, ‘NYG’]]} df2 = pd.DataFrame(d1) print (df2) teams 0 [SF, NYG] 1 [SF, NYG] 2 [SF, NYG] 3 [SF, NYG] 4 [SF, NYG] 5 [SF, NYG] 6 [SF, NYG] df2[[‘team1′,’team2’]] … Read more