Skip to content

Tag: pandas

Remove characters from column

I am trying to remove “0” and “:” from a column in a dataframe. The code I use is, Output: The result does not remove “0” and “:” How can I go about this? Answer You’re missing to assignment of the replacement back to the original column: Though you can ca…

Filter pyspark DataFrame by string match

i would like check substring match between comments and keyword column and find if anyone of the keywords present in that particular row. input expected output Answer The most efficient here is to loop, you can use set intersection: Output: Used input: With a minor variation you could check for substring matc…

two conditions multiplication in pandas

I have the following dataframe, and I am trying to get revenue column by a multiplication between columnA or columnB and columnC. The condition is: if columnB is NaN, then the revenue column = columnA * columnC if columnB is not NaN, then the revenue column = columnB * columnC how do I get this revenue column…