split

Split text on markup in Python

Split text on markup in Python Question: I have the following line of text : <code>stuff</code> and stuff and $LaTeX$ and <pre class="mermaid">stuff</pre> Using Python, I want to break the markup entities to get the following list: [‘<code>’, ‘stuff’, ‘</code>’, ‘ and stuff and $\LaTeX$ ‘, ‘<pre class="mermaid">’, ‘stuff’, ‘</pre>’] So far, I used : …

Total answers: 3

Python Vectorization Split String

Python Vectorization Split String Question: I want to use vectorization to create a column in a pandas data frame that retrieve the second/last part of a string, from each row in a column, that is split on ‘_’. I tried this code: df = pd.DataFrame() df[‘Var1’] = ["test1_test2","test3_test4"] df[‘Var2’] = [[df[‘Var1’].str.split(‘_’)][0]][0] df Var1 Var2 0 …

Total answers: 3

How to split a nested list into separate lists?

How to split a nested list into separate lists? Question: I have a list as follows [[‘Norm,Macdonald’, ’61’, ‘459000’], [‘Paul,McCartney’, ’79’, ‘2789000’], [‘Samuel,Hui’, ’73’, ‘538000’]] For the desired output it would be something like [[‘Norm’, ‘Macdonald’, ’61’, ‘459000’], [‘Paul’, ‘McCartney’, ’79’, ‘2789000’], [‘Samuel’, ‘Hui’, ’73’, ‘538000’]] How should I split it to make it look …

Total answers: 5

How to change names to some friendly names in python?

How to change names to some friendly names in python? Question: I have few dummy function names and I want to transform them as follows: sample case 1 input : getDataType output: Data_Type sample case 2 input: getDatasetID output: Dataset_ID My code is as below: def apiNames(funcName): name = funcName.split("get")[1] print(”.join(‘_’ + char if char.isupper() …

Total answers: 2

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

Split a csv file into multiple files based on a pattern

Split a csv file into multiple files based on a pattern Question: I have a csv file with the following structure: time,magnitude 0,13517 292.5669,370 620.8469,528 0,377 832.3269,50187 5633.9419,3088 20795.0950,2922 21395.6879,2498 21768.2139,647 21881.2049,194 0,3566 292.5669,370 504.1510,712 1639.4800,287 46709.1749,365 46803.4400,500 I’d like to split this csv file into separate csv files, like the following: File 1: time,magnitude …

Total answers: 4

Extracting values after a split to create a new column with a yes or no in Python

Extracting values after a split to create a new column with a yes or no in Python Question: sampleID comorbidities P01 hypertension, diabetes P02 hypertension, diabetes P03 diabetes P04 CHD, asthma P05 asthma, hypertension Hello, I am new to coding and am currently working on some data cleaning using Python and I am trying to …

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

How to map a function over a dataframe field that is a list

How to map a function over a dataframe field that is a list Question: I have spent hours troubleshooting this and really appreciate your help! Each node can have multiple activities, and each activity can have up to two associated grades, which were an ARRAY type in SQL. My goal is to get the minimum …

Total answers: 2