Skip to content
Advertisement

Tag: replace

Pyspark find existing set of rows in a dataframe and replace it with values from another dataframe

I have a Pyspark dataframe_Old (dfo) as below: Id neighbor_sid neighbor division a1 1100 Naalehu Hawaii a2 1101 key-west-fl Miami a3 1102 lubbock Texas a10 1202 bay-terraces California I have a Pyspark dataframe_new (dfn) as below: Id neighbor_sid neighbor division a1 1100 Naalehu Hawaii a2 1111 key-largo-fl Miami a3 1103 grapevine Texas a4 1115 meriden-ct Connecticut a12 2002 east-louisville Kentucky

Replace decimals in floating point numbers

Someone on this platform has already helped me with generating the following code: This code ensures that the last decimal is not a 0 or a 9. However, I would like to have no 0’s nor 9’s in all the decimals that are generated (such that it will not be possible to have a number 1.963749 or 3.459007). It would

Replacing day in date with last day of month

I’ve got a dataframe with column ‘date’, containing yyyy-mm-dd 00:00:00. Python automatically assigned first day of every quarterly month, but I want last day of same month. I’ve tried: and without any success. sample of df: date value 1990-07-01 00:00:00 46.7 1990-10-01 00:00:00 54.2 1991-01-01 00:00:00 38.6 1991-04-01 00:00:00 20 1991-07-01 00:00:00 18.6 I want: date value 1990-07-31 00:00:00 46.7

Python .replace() function doesn’t seem to do anything

I’m trying to modify a table I scraped of Yahoo Finance containing dividends over the last 5 years. An example row of this table is: “1.50 Dividend”. As I want to do calculations with this table I needed only the number in the form of a float. So I used the .replace(“Dividend, “”) function to remove the text part so

pythonic way to replace two character in a string

I have a string ,for example s = “-1+2-3” I want to replace all – to + and all + to -. what I expected is s = +1-2+3 .So I can’t just use s.replace(‘-‘,’+’).replace(‘+’,’-‘),because it return s=-1-2-3,maybe a for loop can help. But I wonder if there is a pythonic way to do so? thanks for all solutions i

Advertisement