Skip to content

Tag: split

Chain df.str.split() in pandas dataframe

Edit: 2022NOV21 How do we chain df.col.str.split() since this returns the split columns if expand = True I am trying to split a column after performing .melt(). If I use assign I end up using the original column and the melted column actually does not even exist. Answer Using expand converts it into a DataFra…

Parse text with uncertain number of fields

I have a file (~50,000 lines) text.txt as below, which contains some gene info from five individuals (AB, BB, CA, DD, GG). The t in the file is a tab seperator. There are also a lot of info that are not useful in the file, and I would like to clean it up. So What I need is to extract

Using Split method or Regex to separate string

In my project I am webscrapping UFC website to gather to the total wins, total losses, and total draws of each UFC athlete. This is part of my code, as I wish to strip the total wins, total losses, and total draws separately: The result is the following: The problem is, I am unable to spew out the total draws…

combining split with findall

I’m splitting a string with some separator, but want the separator matches as well: I can’t find an easy way to combine the 2 lists I get: Into the desired output: Answer From the re.split docs: If capturing parentheses are used in pattern, then the text of all groups in the pattern are also retur…