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:
Tag: string
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 add current date with string like ‘1 hour and 5 second ‘ in python
I have to add datetime lik ‘2019-10-18 11:46:08 ‘+ ‘5 hour 5 second’, 5 hour 5 second is coming from the database and this is not fixed what will be it ie time will be like (15 min, 1 hour 15 min etc) i have tried many thing but getting error how to solve this Answer Firstly store separately the
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
How to remove commas from ALL the column in pandas at once
I have a data frame where all the columns are supposed to be numbers. While reading it, some of them were read with commas. I know a single column can be fixed by However, this works only for series objects and not for entire data frame. Is there an elegant way to apply it to entire data frame since every
What does a star (asterisk) do in f-string?
In the python document 2.4.3. Formatted string literals, it seems possible to write a star followed by an expression in a f-string’s {}, but I cannot find how to use that. What’s that and how I can use it? Is it documented somewhere? To be exact, this is regarding “*” or_expr part of the following BNF. I tried it in
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
How do you scan characters in multi-character multi-string arrays in Python?
I’m working on my first Python project for a device that reads a string from OCR and outputs braille. The braille device can only output 6 letters at a time. I’m stuck trying to scan each character in the 6 character long multi-string array. For simplicity’s sake, for now I only want to print “this is (insert character)” for every
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