string

How to efficiently apply a function to every row in a dataframe

How to efficiently apply a function to every row in a dataframe Question: Given the following table: df = pd.DataFrame({‘code’:[‘100M’,’60M10N40M’,’5S99M’,’1S25I100M’,’1D1S1I200M’]}) that looks like this: code 0 100M 1 60M10N40M 2 5S99M 3 1S25I100M 4 1D1S1I200M I’d like to convert the code column strings to numbers where M, N, D are each equivalent to (times 1), …

Total answers: 5

Extract a number within a string

Extract a number within a string Question: I have a string that looks like this: T/12345/C T/153460/613 I would like to extract the number between the slash / i.e. 12345 and 153460. Sometimes I have 5 numbers, sometimes 6 or more. I tried df[2:7] which extracts from the second to the seventh element but i …

Total answers: 1

How to use regular expression to replace split() in python

How to use regular expression to replace split() in python Question: i have a simple function which takes a s3 uri as input, and extracts its bucket name and key: def fun(s3_uri): bucket = s3_uri.split("/")[2] key = "/".join(s3_uri.split("/")[3:]) return bucket, key My question is: this clearly works, but what if the given s3_uri doesn’t have …

Total answers: 1

Splitting a nested list with a string value in python

Splitting a nested list with a string value in python Question: How would I be able to make a list comprehension that concatenates the input lists with and ‘X’ string as the separator. Note that the expected output will be string. The code below does not work please modify it. val = [[‘_’, ‘_’, ‘_’, …

Total answers: 1

Indexing of strings (molecule SMILES)

Indexing of strings (molecule SMILES) Question: Also, please can someone adjust or give me advice on how to look at the second order of parenthesis. Same process as this, but with only parenthesis in second order (this code is first order). Can you make it so I can easily adjust? By second order I mean …

Total answers: 2

Python datetime format string excluding zeros

Python datetime format string excluding zeros Question: str(datetime.date.today()) I get: 2023-04-01 I need: 2023-4-1 If I format it to remove zeros then I will face an issue if the date is 2023-10-20 How can I do it quick and simple. I need it as a string. Asked By: CODComputerAtWar || Source Answers: You can always …

Total answers: 2

Finding Longest Common Substring

Finding Longest Common Substring Question: I’m trying to find the longest common substring in all DNA strands but in testing I’m using strings of numbers. Here is the funciton I wrote: def lcsm(string_list): strands = sorted(string_list, key = len, reverse = False) longest_motif = ” seq1 = strands[0] seq2 = strands[1] motif = ” for …

Total answers: 1

python string split by comma that appears only between two specific characters that is ><

python string split by comma that appears only between two specific characters that is >< Question: I have a string: <div class="options mceEditable">The membrane is a dynamic structure, and its constituents are in constant movement.</div>, <div class="options mceEditable">The lipids component of the membrane constitutes a bilayer of hydrophilic ends</div>, <div class="options mceEditable">The lipid content of …

Total answers: 3