Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

I'm trying to replace a specific value in my dataframe

i have a row that consists of days of the week but there is a random number in there and i just want to replace that number with "Thur" i tried . replace but my then all the other columns in my df disappeared except for the index and the column that had the days of the week

sales=sales["day of week"].replace(0, "Thru")

^^^this is the code i used
this is the df before i ran the code
this is the df before i ran the code

This is the df after i ran the code

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

This is the df after i ran the code

>Solution :

You assign only the day of week column into sales, so it makes sense you get only one column. Try:

sales["day of week"]=sales["day of week"].replace(0, "Thru")

If it doesn’t work (because day of week is an object type column), try:

sales["day of week"]=sales["day of week"].replace('0', "Thru")
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading