Skip to content
Advertisement

Tag: string

Returning entries from a data set that contain a specific string in Python

I have a data set called df with the information of the name of the Drugs that has been administered. The column “drug_name” consists of all the various drug names. I would like to extract entries that only contain a specific name of the drugs. I have tried the .str.contain method df_adr= df[df[“drug_name”].str.contains(“epinephrine”)==True] This works but the problem is it

Is the implicit conversion of strings that have only whitespace between them to a single string any different from concatenation?

I came across this line in the Python documentation: String that are part of a single expression and have only whitespace between them will be implicitly converted to a single string literal. That is, (“spam ” “eggs”) == “spam eggs”. Another way to see this is, “spam” “eggs” == “spam” + “eggs” Firstly, apart from the concept that ‘explicit is

Change position of a line with a specific string, using python

I am new to coding, trying to find a simple python code for re-arranging some lines. Lines have specific string to select. Those lines with this specific string need to be moved. Original File content: Note: the attribute line with “last” in it, this whole line should go to the end of each element’s attribute list. New file format: Appreciate

Advertisement