Skip to content
Advertisement

Tag: string

Pandas – Duplicate Rows and Slice String

I’m trying to create duplicate rows during a dataframe on conditions. For example, I have this Dataframe. And I would like to get the following output: Answer For pandas 0.25+ is possible use DataFrame.explode with splitted values by Series.str.split and for remark column list comprehension with filtering: And we get the following result:

How to remove sub-string starting and ending with something?

How can I remove a sub-string from a string starting and ending with a certain character combination like: That I want as result: I tried something like this but this does not work. Is there a way to implement this? Answer This could work: Regex101 EDIT : after clarification by the OP, changed the answer to use lazy quantifier instead

How to extract specific line in text file

I am text mining a large document. I want to extract a specific line. I want to extract the description immediately under ITEM DESCRIPTION. I have tried many unsuccessful attempts. My latest attempt was: But it did not find the text. Is there a way to find ITEM DESCRIPTION and get the line after it or something similar? Answer The

Why does this pandas str.extract pattern work?

I have a dataframe “movies” with column “title”, which contains movie titles and their release year in the following format: The Pirates (2014) I’m testing different ways to extract just the title portion, which in the example above would be “The Pirates”, into a new column. I used pandas Series.str.extract() and found a regex pattern that works, but I’m not

Python can’t describe two varibles

I am trying to make a simple program to calculate the area of a triangle. But at the end, python does not recognize the str function I am using. I have little to no experience on Python so if this is a stupid question, then that is why. I have tried renaming the variables and looking at other questions on

Finding Subarrays of Vowels from a given String

You are given a string S, and you have to find all the amazing substrings of S. Amazing Substring is one that starts with a vowel (a, e, i, o, u, A, E, I, O, U). Input The only argument given is string S. Output Return a single integer X mod 10003, here X is number of Amazing Substrings in

Advertisement