substring

Regex: capture specific string with conditions

Regex: capture specific string with conditions Question: Im trying to just capture the following string: u00 because i need to replace it to u00. Sometimes this characters appear with a before, in that case, i don’t want to capture it. At other times, the simbol is ", i want to capture it, but just the …

Total answers: 2

Printing substring from one dataframe to another dataframe

Printing substring from one dataframe to another dataframe Question: In the df_input[‘Visit’ ] column, there are three different timepoints that I would like to extract and have print into a new dataframe (df_output). The time points are Pre, Post, and Screening. I essentially would like to make a for loop (or just a single code …

Total answers: 2

Breaking a python string in pandas dataframe

Breaking a python string in pandas dataframe Question: I have a column ‘released’ which has values like ‘June 13, 1980 (United States)’ I want to get the year from this string so I tried using the following code df[‘year_correct’] = df[‘released’].astype(str).str[‘,’:'(‘] But it is returning all the values as Nan in the new ‘year_correct’ column. …

Total answers: 1

How to save all occurences of a substring to an array in Python

How to save all occurences of a substring to an array in Python Question: I want to save each value between "(" and ")" from the string "obs1" to an array. obs1 = "3341 – SSS – ELO CRED – (48,00) 4526 – SSS 7837 – SSS – MASTER DEB – (25,00) 2830 – SSS …

Total answers: 1

Python: What is an efficient way to loop over a list of strings and group substrings in the list?

Python: What is an efficient way to loop over a list of strings and group substrings in the list? Question: Background mylist = [‘abc123’, ‘abc123456’, ‘abc12355’, ‘def456’, ‘ghi789’, ‘def4567’, ‘ghi78910’, ‘abc123cvz’] I would like to find and group the substrings in the list into a list of tuples where the first element of the tuple …

Total answers: 3

Replacing a set of characters in a string

Replacing a set of characters in a string Question: I have this code below trying to remove the leading characters of a string by using an indicator to where to stop the trim. I just want to know if there are some better ways to do this. #Get user’s input: file_name file_name = str.casefold(input("Filename: ")).strip() …

Total answers: 1