I want to essentially find and replace using python.
However, I want to say if a cell contains something, then replace with what I want.
I know
str.replace('safsd','something else')
However, I am not sure how to specify how to get rid of EVERYTHING in that cell. Do I use *
? I am not too familiar with that in python but I know in the bash shell *
references to everything...
I have
df['Description']
that can contain 'optiplex 9010 for classes and research'
which I just want to replace with 'optiplex 9010'
. Or 'macbook air 11 with configurations...etc.'
and I want simply 'macbook air 11'
I am aiming for...
if Df['Description'].str.contains('macbook air 11')
then Df['Description'].str.replace(' (not sure what I put in here) , 'mabook air 11')
Any help/ideas?
Thanks!
**Additional info that may be helfpul...
I am working with thousands of different user inputs. So the 'Descriptions' of what someone has purchased is not going to be the same at all in context, wording, structure, etc. etc. I can either manually go into excel and filter by what contains 'optiplex 9010' and then replace everything with a simple description , doing the same for macbooks, etc.
I figured there may be some simpler way using pandas/python .str.contains and .str.replace.
Hope that extra info helps! Let me know